我正在尝试创建一个聊天应用程序。当前的聊天布局如下所示

相应的布局文件是
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.nirmal.chatadapter.MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile_image"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:src="@drawable/iconuser"
app:civ_border_width="2dp"
app:civ_border_color="@color/White"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/marginLeftForToolbar"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/White"
android:text="UserName Here"
android:layout_marginTop="@dimen/marginTopBottomForBubble"
android:id="@+id/user_name"
android:textSize="@dimen/textMedium"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/White"
android:text="User details Here"
android:layout_marginTop="@dimen/marginTopBottomForBubble"
android:id="@+id/user_details"
android:textSize="@dimen/textSmall"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar"
android:layout_marginTop="@dimen/recyclerViewMargin"
android:isScrollContainer="true"
android:id="@+id/chatRecycler"
android:layout_above="@+id/chatBoxAndSend">
</android.support.v7.widget.RecyclerView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:layout_marginBottom="5dp"
android:id="@+id/chatBoxAndSend">
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:minWidth="50dp"
android:maxWidth="50dp"
android:id="@+id/chatBox"
android:paddingStart="@dimen/cardViewPadding"
android:background="@drawable/rounded_chat_box"
android:layout_margin="@dimen/marginForChatBox"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:background="@drawable/oval_button"
android:minWidth="50dp"
android:maxWidth="50dp"
android:text="Send"
android:imeOptions="flagNoExtractUi"
android:id="@+id/chatSendButton"
android:layout_margin="@dimen/marginForChatBox"
android:textColor="@color/Black"
/>
<!--<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1"
android:id="@+id/send_button"
android:src="@drawable/send"
android:background="@drawable/oval_button"
android:layout_marginBottom="@dimen/marginForChatBox"
android:layout_marginTop="@dimen/marginForChatBox"
android:layout_marginEnd="@dimen/marginForChatBox"
/>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1"
android:id="@+id/send_button"
android:src="@drawable/send"
app:civ_border_width="2dip"
android:layout_marginEnd="@dimen/marginForChatBox"
app:civ_border_color="@color/greenChatColor"/>-->
</LinearLayout>
</RelativeLayout>
</ScrollView>当我打开我的软键盘时,布局是这样的

我已经在我的清单文件中添加了这个
android:windowSoftInputMode="adjustPan|stateHidden"输出结果和我预期的不一样。我希望recyclerview在屏幕中央动态调整大小,工具栏和编辑文本保持完全可见。
正如您所看到的,工具栏已被向上推送,甚至在滚动时也不可见。编辑文本被键盘给出的建议部分隐藏。我看到的一些帖子要求我添加一个滚动视图,我这样做了,但仍然是相同的结果。我该如何解决这个问题?
发布于 2019-08-16 16:55:13
如果你想在SoftInput打开或关闭时调整RecyclerView的大小,你可以使用下面的单行代码
((LinearLayoutManager)myRecyclerView.getLayoutManager()).setStackFromEnd(true);有关更多信息,请阅读此帖子:https://trinitytuts.com/tips/resize-recyclerview-on-android-softinput-keyboard-appear/
我希望这段代码能帮助你
发布于 2017-08-07 21:55:51
标志adjustPan是错误的。请改用adjustResize:
android:windowSoftInputMode="adjustResize|stateHidden"adjustPan所做的相当于放大图片而不是屏幕,然后平移--也就是说,移动图片,让你看到它的不同部分。(例如,就像google地图中的地图)。
https://stackoverflow.com/questions/45540784
复制相似问题