1

我正在创建 android 聊天应用程序。
但是,当键盘打开时,它几乎不会覆盖 EditText。
如果我使用“adjustResize”,它不会覆盖 EditText,但会覆盖 ListView。

显现:

android: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>

键盘关闭

键盘被打开

4

2 回答 2

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 layoutwhich containslistview然后它应该使用Relative layoutand inside that解决您的问题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"which containsEditText和 send icon

于 2015-10-18T03:45:26.077 回答
0

在我看来,“adjustResize”是你最好的选择。这将调整列表视图的大小以适应键盘。您可以在列表中使用 bottomPadding。“adjustPan”不会有太大帮助,因为它会改变整个布局并且看起来不太好。

于 2015-10-18T04:03:24.830 回答