KeyBoard出现时,在ListView上编辑文本

时间:2015-04-07 14:27:40

标签: java android xml listview android-softkeyboard

所以,我正在开发一个在ListView下面有Listview,EditText和Button的应用程序。像这个版画屏幕:enter image description here

问题是:当我点击EditText时,EditText会上升并保持领先于我的Listview,就像这个printcreen:

enter image description here

在我的Mainfest中,我已经添加了windowSoftInputMode =“AdjustResize”和windowSoftInputMode =“adjustPan”,并且可以正常工作。

这是我的XML:

<RelativeLayout     xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="400dp"
android:layout_height="match_parent"
tools:context=".MainActivity">

<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:ems="10"
    android:id="@+id/editText"
    android:hint="Senha"
    android:textColor="#000000"
    android:layout_marginBottom="22dp"
    android:layout_above="@+id/button"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Conectar"
    android:id="@+id/button"
    android:textColor="#000000"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="39dp" />

    <ListView
        android:layout_width="330dp"
        android:layout_height="260dp"
        android:id="@+id/listView"
        android:background="@drawable/border"
        android:stackFromBottom="true"
        android:transcriptMode="normal"
        android:layout_marginLeft="63dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
              </RelativeLayout>

任何人都可以帮我解决这个问题吗?谢谢你的帮助!

2 个答案:

答案 0 :(得分:1)

试试这个。并根据您的需要增加保证金 我在手机上测试了这个。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >

        <ListView
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/border" >
        </ListView>
    </LinearLayout>

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="22dp"
        android:ems="10"
        android:hint="Senha"
        android:inputType="textPassword"
        android:textColor="#000000" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="39dp"
        android:text="Conectar"
        android:textColor="#000000" />

</LinearLayout>

答案 1 :(得分:0)

在此代码段

下添加RequestFocus
 <ListView
        android:layout_width="330dp"
        android:layout_height="260dp"
        android:id="@+id/listView"
        android:background="@drawable/border"
        android:stackFromBottom="true"
        android:transcriptMode="normal"
        android:layout_marginLeft="63dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
    <RequestFocus/> 
</Relativelayout>
相关问题