【发布时间】:2017-07-22 08:21:47
【问题描述】:
我正在尝试制作聊天布局。问题是当我关注 EditText 时,软键盘出现并将所有内容都向上推。我希望它只推送带有发送指令的底部部分,以便顶部(棕色)标题部分和带有消息的 recyclerview 仍然可见。 facebook messenger 应用程序拥有的东西。我尝试将“调整平移,调整大小”和清单文件中的所有内容,但没有奏效。这是我在没有焦点时的默认布局:
这是当我按下 EditText 并出现键盘并将所有内容向上移动时:
基本上我希望所有元素始终可见,因此当键盘向上推时,标题、消息和发送仍然对用户可见。
这是我的布局代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_profile"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:layout_marginBottom="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/iv_profile"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/img_back" />
<TextView
android:id="@+id/tv_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp" />
</LinearLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/ll_profile"
android:fillViewport="true"
android:isScrollContainer="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="@+id/view_line"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:background="@color/gray_light_trans" />
<LinearLayout
android:id="@+id/ll_send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="10">
<EditText
android:id="@+id/et_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="9"
android:hint="Message" />
<Button
android:id="@+id/btn_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Send" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_chat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/ll_send"
android:layout_below="@id/view_line" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
【问题讨论】:
-
你在清单中为
android:windowSoftInputMode设置了什么? -
正如我在帖子中所写的那样,我尝试了在每种组合中调整平移和调整大小,但仍然没有效果
-
adjustPan 会移动您的内容,但如果您设置了 adjustResize 或未设置任何内容,则您的内容不应移动。
-
尝试删除所有内容,仍然没有进展
-
有趣。我试过你的代码对我来说工作正常。你也可以给我们看看你的清单吗?
标签: android xml user-interface android-softkeyboard