【问题标题】:Virtual keyboard block the button below when click the EditText View单击 EditText 视图时,虚拟键盘会阻止下面的按钮
【发布时间】:2015-05-05 02:01:13
【问题描述】:

我的活动底部附近有一个 editText 视图。当我单击它并显示键盘时,它会阻止editText下方的按钮。我使用 android:windowSoftInputMode="adjustResize" 或 "adjustPan" 但不能按我的意愿工作。

以下是一些截图:

原图:

单击编辑文本时:

我想要的视图:

这是我的代码:

<include
    android:id="@+id/headerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    layout="@layout/section_header" />

<ScrollView
    android:id="@+id/scrollview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/headerView"
    android:fillViewport="true" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <com.wom.wom.GTextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="80dp"
            android:gravity="center_horizontal"
            android:text="NOT OUR MEMBER YET?"
            android:textSize="28sp" />

        <com.wom.wom.GTextView
            android:layout_width="200dp"
            android:layout_height="50dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="50dp"
            android:background="@drawable/rounded_corner0"
            android:gravity="center"
            android:text="TAKE THE TOUR"
            android:textSize="18sp" />

        <com.wom.wom.ATextView
            android:id="@+id/join_now"
            android:layout_width="200dp"
            android:layout_height="50dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="50dp"
            android:layout_marginTop="30dp"
            android:background="@drawable/rounded_corner_green"
            android:gravity="center"
            android:text="JOIN NOW"
            android:textColor="#FFF"
            android:textSize="18sp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/m_dash_black"
            android:gravity="center_horizontal|bottom"
            android:orientation="horizontal" >

            <com.wom.wom.ATextView
                android:id="@+id/tv_add_card"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginRight="50dp"
                android:gravity="center"
                android:text="ADD CARD"
                android:textColor="@drawable/text_selector_wo"
                android:textSize="22sp" />

            <View
                android:id="@+id/vDottedLine"
                android:layout_width="30dp"
                android:layout_height="match_parent"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/vdash_line2"
                android:layerType="software" />

            <com.wom.wom.ATextView
                android:id="@+id/tv_scan_card"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginLeft="50dp"
                android:gravity="center"
                android:text="SCAN CARD"
                android:textColor="@drawable/text_selector_wo"
                android:textSize="22sp" />
        </LinearLayout>

        <RelativeLayout
            android:id="@+id/add_card"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/card_bg" >

            <EditText
                android:id="@+id/card_number"
                android:layout_width="300dp"
                android:layout_height="50dp"
                android:layout_below="@+id/tv3"
                android:layout_marginLeft="50dp"
                android:layout_marginTop="100dp"
                android:background="#FFF"
                android:hint="14 Digit Number"
                android:paddingLeft="5dp"
                android:textSize="20sp" />

            <EditText
                android:id="@+id/password"
                android:layout_width="300dp"
                android:layout_height="50dp"
                android:layout_below="@+id/card_number"
                android:layout_marginLeft="50dp"
                android:layout_marginTop="20dp"
                android:background="#FFF"
                android:hint="Password"
                android:paddingLeft="5dp"
                android:textSize="20sp" />

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1" />

            <com.wom.wom.ATextView
                android:id="@+id/ib_add_card"
                android:layout_width="200dp"
                android:layout_height="50dp"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="20dp"
                android:background="@drawable/rounded_corner_red"
                android:gravity="center"
                android:text="ADD MY CARD"
                android:textColor="#FFF"
                android:textSize="18sp" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/scan_card"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/scan_bg"
            android:visibility="gone" >

            <com.wom.wom.ATextView
                android:id="@+id/ib_scan_card"
                android:layout_width="200dp"
                android:layout_height="50dp"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="20dp"
                android:background="@drawable/rounded_corner_red"
                android:gravity="center"
                android:text="SCAN MY CARD"
                android:textColor="#FFF"
                android:textSize="18sp" />
        </RelativeLayout>
    </LinearLayout>
</ScrollView>

</RelativeLayout>

【问题讨论】:

  • 小键盘打开时,您是否尝试过滚动?另外,试试adjustPan
  • 我想显示显示页面而不是自己滚动。并且 adjustPan 也不起作用

标签: android keyboard android-edittext window-soft-input-mode adjustpan


【解决方案1】:

你应该在manifest文件的&lt;activity&gt;标签中添加这个属性。

<activity
    android:windowSoftInputMode="adjustPan"
    //rest attributes ...
/>

编辑

如果在manifest 中添加adjustPan 不起作用,则将其添加到java 代码中,

设置contentView写入后onCreate()方法内,

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

【讨论】:

  • @DannyHo 检查我已经编辑了我的答案,你也可以通过编程方式完成,一旦你尝试过就告诉我。
  • 如果我把它放在代码中它仍然不起作用。和截图2一样
  • @DannyHo 你的项目的minSdkVersion是什么?
  • @DannyHo 你也应该试试把android:imeOption="flagNoFullscreen"
  • @DannyHo 你也应该把&lt;ScrollView&gt;放到你的布局中。
猜你喜欢
  • 1970-01-01
  • 2023-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-23
相关资源
最近更新 更多