我正在尝试制作一个即时聊天界面。
正常:

但当我点击EditText时,键盘会弹出来,但EditText不会随着键盘一起弹出来,而且ToolBar中的内容也会消失。如下所示:

我尝试设置android:windowSoftInputMode,但问题仍然存在。我认为这个问题可能是由于xml文件结构造成的。下面是我的xml文件结构:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout >
<android.support.design.widget.AppBarLayout >
<android.support.v7.widget.Toolbar >
<TextView />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<LinearLayout>
<android.support.v7.widget.RecyclerView />
<com.loopeer.shadow.ShadowView>
<LinearLayout>
<ImageView/>
<EditText/>
<ImageView />
</LinearLayout>
</com.loopeer.shadow.ShadowView>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>阴影视图提供了类似于CardView的阴影效果。谢谢你的帮忙!
发布于 2019-02-19 13:06:22
尝试这个示例聊天ui布局,它应该工作得很好:
<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">
<android.support.v7.widget.RecyclerView
android:id="@+id/rvcommlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/view">
</android.support.v7.widget.RecyclerView>
<!-- A horizontal line between the chatbox and RecyclerView -->
<View
android:layout_width="0dp"
android:id="@+id/view"
android:layout_height="2dp"
android:background="#dfdfdf"
android:layout_above="@+id/layout_chatbox"
android:layout_marginBottom="0dp"
/>
<LinearLayout
android:id="@+id/layout_chatbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:background="#ffffff"
android:gravity="bottom"
android:minHeight="48dp"
android:orientation="horizontal">
<EditText
android:id="@+id/tvcomm"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:hint="Enter message"
android:maxLines="6" />
<Button
android:id="@+id/comment"
android:layout_width="64dp"
android:layout_height="48dp"
android:layout_gravity="bottom"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:gravity="center"
android:text="SEND"
android:textSize="14dp" />
</LinearLayout>
</RelativeLayout>https://stackoverflow.com/questions/54759162
复制相似问题