我在RecyclerView
内有EditText
和CardView
。活动的目的是聊天。因此RecyclerView
包含发送和接收的所有消息,CardView
是用户键入消息的位置。出现问题,我需要在键盘弹出时移动内容。现在,这似乎不是一个简单的问题。
我尝试了所有这些问题:
而且,大多数解决方案都归结为android:windowSoftInputMode
。我尝试过,切换到adjustPan
和adjustResize
。以下是我的活动的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#F0F0F0"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingStart="10dp"
android:paddingEnd="10dp"
tools:context="com.devpost.airway.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/chatView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.CardView
android:layout_alignParentBottom="true"
android:layout_marginTop="10dp"
app:cardElevation="0dp"
app:cardCornerRadius="10dp"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="50dp">
<EditText
android:id="@+id/chat_input"
android:paddingStart="2dp"
android:paddingEnd="2dp"
android:inputType="text"
android:imeOptions="actionSend"
android:background="@null"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v7.widget.CardView>
</RelativeLayout>
并且adjustPan
确实以非常模糊的方式工作,我已经添加了下面的屏幕截图,请看一下:
图片-1
图片-2
现在,从Image-1和Image-2来看,几乎没有问题:
ActionBar
向上移动。所以,问题是:
除了允许android:windowSoftInputMode
改变它喜欢的方式之外,是否可以手动覆盖任何方法并自行实现?请帮助。
答案 0 :(得分:-1)
<android.support.v7.widget.RecyclerView
android:id="@+id/chatView"
android:layout_width="match_parent"
android:layout_above="@+id/editorCard"
android:layout_height="wrap_content" />
<android.support.v7.widget.CardView
android:id="@+id/editorCard"
android:layout_alignParentBottom="true"
android:layout_marginTop="10dp"
app:cardElevation="0dp"
app:cardCornerRadius="10dp"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="50dp">
<!--your editor code-->
</android.support.v7.widget.CardView>
wrap_content
和layout_above
是所需行为的主要变化
并在softinputmethod
中,将其设为adjustPan|adjustResize