Android 使用RecyclerView和底部固定的EditText协调布局

Android 使用RecyclerView和底部固定的EditText协调布局,android,android-layout,android-coordinatorlayout,android-appbarlayout,Android,Android Layout,Android Coordinatorlayout,Android Appbarlayout,我正在开发一个聊天屏幕。它包括用于用户配置文件图像的折叠工具栏布局、用于消息列表的RecyclerView和用于发送消息的编辑框。我不知道是否有可能将编辑框固定到底部屏幕,并阻止它与屏幕的其余部分一起滚动 如果我将CoordinatorLayout包装成垂直线性布局,并将EditText放在CoordinatorLayout之外,我几乎实现了我想要的效果。不过,在这种情况下,键盘行为与RecyclerView分离—当您打开键盘时,它不会向上/向下滚动 如果我尝试将EditText放入Coordi

我正在开发一个聊天屏幕。它包括用于用户配置文件图像的折叠工具栏布局、用于消息列表的RecyclerView和用于发送消息的编辑框。我不知道是否有可能将编辑框固定到底部屏幕,并阻止它与屏幕的其余部分一起滚动

如果我将CoordinatorLayout包装成垂直线性布局,并将EditText放在CoordinatorLayout之外,我几乎实现了我想要的效果。不过,在这种情况下,键盘行为与RecyclerView分离—当您打开键盘时,它不会向上/向下滚动

如果我尝试将EditText放入Coordinator或布局中,它将滚动出屏幕,我不知道是否需要为它设置任何特殊行为

我的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:id="@+id/keyboard_listener"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical"
>

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/coordinator"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    >

    <RecyclerView
       android:id="@android:id/list"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:clickable="true"
       android:clipToPadding="false"
       android:focusableInTouchMode="true"
       android:paddingBottom="20dp"
       android:scrollbarStyle="outsideOverlay"
       android:scrollbars="vertical"
       android:transcriptMode="normal"
       app:layout_behavior="@string/appbar_scrolling_view_behavior"
       />

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        >

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/screen_toolbar_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
            app:titleEnabled="false"
            >

            <FrameLayout
                android:id="@+id/toolbar_fragment_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                />

            <Toolbar
                android:id="@+id/screen_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@android:color/transparent"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:layout_collapseMode="pin"
                />

        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

        <EditText
            android:id="@+id/messageEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@null"
            android:hint="@string/send_hint"
            android:inputType="textCapSentences|textMultiLine"
            android:maxLength="2000"
            android:maxLines="4"
            android:padding="10dp"
            android:textSize="14sp"/>

</LinearLayout>

朋友,在编辑文本中添加这个,就像浮动操作按钮一样

   app:layout_anchor="@id/your bottom view id"
   app:layout_anchorGravity="bottom|right|end"

好的,如果您真的想在屏幕底部编辑文本,您应该将其从协调布局中排除,并将其放在活动布局中。第二个应该是
RelativeLayout
,这样你就可以给EditText属性,比如
android:layout\u alignParentBottom=“true”
@piotrek1543我感谢你的努力,但很抱歉-你真的帮不上忙:)请再次阅读我的问题-我确实将CoordinatorLayout包装成了一个LinearLayout,我的编辑文本按我希望的那样固定。但键盘不会滚动回收服务关于您的协调人布局问题,安卓:isScrollContainer=“true”将解决此问题,名称有点误导,但注释是关键:如果视图用作滚动容器,则设置此选项,这意味着它可以调整大小以缩小整个窗口,从而为输入法留出空间。如果未设置,如果“scrollbars”设置了垂直滚动条,则默认值将为true,否则将为false。不幸的是,我没有解决您的问题的方法,但您现有的设置足以解决我的问题。希望这能给你一些安慰?@Anton你找到什么解决办法了吗?但在这种情况下,EditText位于recycler视图之上