2
我在CardView
内有RecyclerView
和EditText
。该活动的目的是聊天。因此RecyclerView
包含所有发送和接收的消息,并且CardView
是用户输入消息的地方。出现问题时,我需要在弹出键盘时将内容向上移动。现在,这似乎不是一个简单的问题。如何在弹出键盘时将视图的内容向上推?
我尝试了所有这些问题:
- Push up content when clicking in edit text
- How to move the layout up when the soft keyboard is shown android
- Move layouts up when soft keyboard is shown?
而且,解决最归结为改变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
确实在一个非常模糊的方式工作,我已经添加下面的截图,请看看:
IMAGE-1
IMAGE-2
现在,显然从图片-1和图像2中,有几个问题:
- 的
ActionBar
向上移动。 - 当键盘弹出它增加了一个过渡动画
- 它推动了整个RecyclerView了
所以,问题是:
手动是否可以覆盖任何方法和实施的事情我自己,除了允许android:windowSoftInputMode
改变它喜欢的方式?请帮助。
几乎没有进行任何更改,不会做任何事情。 @钢铁侠 – OBX