出现键盘时在 ListView 上编辑文本
EditText over ListView when KeyBoard appears
所以,我正在开发一个应用程序,它有一个 Listview、一个 EditText 和一个位于 ListView 下方的按钮。喜欢这个打印屏幕:
问题是:当我在 EditText 中单击时,EditText 上升并保持在我的 Listview 前面,就像这样的打印屏幕:
在我的 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>
谁能帮我解决这个问题?感谢您的帮助!
在此代码段下方添加 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>
试试这个。并根据您的需要添加保证金。
我在我的手机上测试了这个。
<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>
所以,我正在开发一个应用程序,它有一个 Listview、一个 EditText 和一个位于 ListView 下方的按钮。喜欢这个打印屏幕:
问题是:当我在 EditText 中单击时,EditText 上升并保持在我的 Listview 前面,就像这样的打印屏幕:
在我的 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>
谁能帮我解决这个问题?感谢您的帮助!
在此代码段下方添加 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>
试试这个。并根据您的需要添加保证金。
我在我的手机上测试了这个。
<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>