我正在创建Android聊天应用程序 但是,当键盘打开时,它几乎不会覆盖EditText 如果我使用“adjustResize”,它不会覆盖EditText,但它涵盖了ListView。
清单:
机器人:windowSoftInputMode = “stateAlwaysHidden | adjustPan”
布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lV_chat"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="@+id/linearLayout3"
android:background="@color/gray"
android:layout_below="@+id/toolbarChat"
android:divider="@null"
android:paddingRight="@dimen/space_6dp"
android:paddingLeft="@dimen/space_6dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="@dimen/chat_text_input_height"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:id="@+id/linearLayout3"
android:background="@color/white">
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:inputType="textMultiLine"
android:ems="10"
android:id="@+id/eT_chat"
android:layout_weight="1"
android:background="@color/transparency"
android:layout_marginLeft="@dimen/space_20dp"
android:textCursorDrawable="@null" />
<ImageButton
android:layout_width="@dimen/chat_send_button_width"
android:layout_height="match_parent"
android:id="@+id/iB_send"
android:background="@color/light_blue"
android:src="@drawable/ic_send"
android:scaleType="centerInside" />
</LinearLayout>
</RelativeLayout>
答案 0 :(得分:0)
尝试做这样的事情
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:id="@+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginBottom="50dp"
android:fitsSystemWindows="true">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lV_chat"
android:divider="@null"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:inputType="textMultiLine"
android:ems="10"
android:id="@+id/eT_chat"
android:layout_weight="1"
android:textCursorDrawable="@null" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/iB_send"
android:src="@mipmap/ic_launcher"
android:scaleType="centerInside" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
您可以android:layout_marginBottom="your edittext's layout's width"
main layout
包含listview
,然后它应该使用Relative layout
并在Linear layout
内修复您的问题。
并记住不要将这些行添加到linear layout
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
相对布局应包含android:layout_alignParentBottom="true"
,其中包含EditText
并发送icon
。
答案 1 :(得分:0)
在我看来,“adjustResize”是你最好的选择。这会调整列表视图的大小以适应键盘。您可以在列表中使用bottomPadding。 “adjustPan”不会有太大帮助,因为它会改变整个布局,看起来不会很好。