Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 当键盘弹出时,如何向上推视图的内容?_Android_Android Layout_Keyboard - Fatal编程技术网

Android 当键盘弹出时,如何向上推视图的内容?

Android 当键盘弹出时,如何向上推视图的内容?,android,android-layout,keyboard,Android,Android Layout,Keyboard,我在CardView中有一个RecyclerView和一个EditText。活动的目的是聊天。因此,RecyclerView包含发送和接收的所有消息,而CardView是用户键入消息的地方。说到问题,我需要在键盘弹出时将内容向上移动。现在,这似乎不是一个简单的问题 我试过所有这些问题: 而且,解决大多数问题的办法可以归结为改变android:WindowsofInputMode。我试过了,切换到adjustPan和adjustResize。以下是我的活动代码: <?xml vers

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

我试过所有这些问题:

而且,解决大多数问题的办法可以归结为改变android:WindowsofInputMode。我试过了,切换到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

现在,从图1和图2可以清楚地看出,有几个问题:

操作栏向上移动。 当键盘弹出时,它会添加一个过渡动画 它将整个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>
上面的包装内容和布局是所需行为的关键更改

在softinputmethod中,将其设置为adjustPan | adjustResize

上面的包装内容和布局是所需行为的关键更改


在softinputmethod中,使其调整pan | adjustResize

几乎不做任何更改,也不做任何事情@IronmanHardly做了任何改变,什么也没做@铁人