繁体   English   中英

键盘弹出时如何上推视图的内容?

[英]How to push the contents of a View up when Keyboard pops up?

我在CardView有一个RecyclerView和一个EditText 活动的目的是聊天。 因此, RecyclerView包含所有已发送和接收的消息,而CardView是用户键入消息的地方。 出现问题时,我需要在键盘弹出时将内容上移。 现在,这似乎不是一个简单的问题。

我尝试了所有这些问题:

而且,大多数解决方案归结为更改android:windowSoftInputMode 我尝试过,切换到adjustPanadjustResize 这是我的活动的代码:

    <?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

图像1

影像2

在此处输入图片说明

现在,从Image-1和Image-2可以清楚地看到几个问题:

  • ActionBar向上移动。
  • 弹出键盘时,会添加过渡动画
  • 它将整个RecyclerView向上推

因此, 问题是:

除了允许android:windowSoftInputMode更改其喜欢的方式之外,是否可以手动覆盖任何方法并自己实现事情? 请帮助。

<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_contentlayout_above是所需行为的关键更改

然后在softinputmethod ,使其为adjustPan|adjustResize

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM