[英]How to push the contents of a View up when Keyboard pops up?
I have a RecyclerView
and an EditText
inside a CardView
. 我在CardView
有一个RecyclerView
和一个EditText
。 Purpose of the activity is to chat. 活动的目的是聊天。 So the RecyclerView
contains all the messages sent and received, and the CardView
is where the user types the messages. 因此, RecyclerView
包含所有已发送和接收的消息,而CardView
是用户键入消息的地方。 Coming to the problem, I need to move the contents up when the Keyboard pops up. 出现问题时,我需要在键盘弹出时将内容上移。 Now, this doesn't seems to be a simple problem. 现在,这似乎不是一个简单的问题。
I tried all these Questions: 我尝试了所有这些问题:
And, the solution to most comes down to altering android:windowSoftInputMode
. 而且,大多数解决方案归结为更改android:windowSoftInputMode
。 Which I tried, switching to adjustPan
and adjustResize
. 我尝试过,切换到adjustPan
和adjustResize
。 Here is the code to my Activity: 这是我的活动的代码:
<?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>
And adjustPan
does work in a very vague way, I've added the screenshot below, kindly take a look : adjustPan
确实以一种非常模糊的方式工作,我在下面添加了屏幕截图,请看一下:
IMAGE-1 图像1
IMAGE-2 影像2
Now, clearly from Image-1 and Image-2, there are few issues: 现在,从Image-1和Image-2可以清楚地看到几个问题:
ActionBar
is moved up . ActionBar
向上移动。 So, the question is: 因此, 问题是:
Is it manually possible to override any methods and implement things myself up, other than allowing the android:windowSoftInputMode
to change the way it prefers? 除了允许android:windowSoftInputMode
更改其喜欢的方式之外,是否可以手动覆盖任何方法并自己实现事情? Kindly help. 请帮助。
<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
and layout_above
are the key changes for the desired behavior wrap_content
和layout_above
是所需行为的关键更改
and in softinputmethod
, make it adjustPan|adjustResize
然后在softinputmethod
,使其为adjustPan|adjustResize
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.