如何使用ScrollView正确定位LinearLayout?

时间:2016-12-08 01:29:21

标签: android android-layout

我在片段布局中使用此代码:

<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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    tools:context="com.app.MainFragment">

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:scrollbars="vertical"
        android:scrollbarAlwaysDrawVerticalTrack="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@color/colorDivider">
        <android.support.v7.widget.RecyclerView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="500dp"
            android:scrollbars="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            />
    </LinearLayout>
    </android.support.v4.widget.NestedScrollView>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:layout_alignParentBottom="true"
        android:weightSum="2"
        >

        <EditText
            android:id="@+id/edit_text"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.91"
            android:layout_marginLeft="10dp"
            android:textColor="@color/colorPrimaryDark"
            android:textColorHint="@color/colorPrimaryDark"
            android:theme="@style/btmedtext"
            android:textColorHighlight="@color/colorPrimary"
            android:hint="Send message"
            android:inputType="textMultiLine"
            android:maxLines="6"
            android:scrollbars="vertical">
        </EditText>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/button_send"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_marginRight="3dp"
            android:layout_marginLeft="10dp"
            android:layout_marginBottom="16dp"
            android:layout_gravity="bottom|end"
            android:src="@drawable/ic_mic_white_24dp"/>

    </LinearLayout>

</RelativeLayout>

结果是:

enter image description here

我的问题是:如何避免在Recyclerview上浮动LinearLayout(EditText + FloatingActionButton)? 我想将这个LinearLayout保持在底部,当使用EditText时,ScrollView应该跳过它。

enter image description here

3 个答案:

答案 0 :(得分:0)

不幸的是,当使用浮动操作按钮时,您似乎唯一的选择是完全移动按钮,隐藏按钮,或者您可以动态添加空容器,从而移动阻止的内容。

查看THIS库。如果移动或空容器不可用,您可以使用它。它允许您保留按钮并在需要时显示它。

Floating Action Button Hide Library

答案 1 :(得分:0)

我希望这能解决你的问题

<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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context="com.app.MainFragment">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/colorDivider">
        <android.support.v7.widget.RecyclerView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical"
            android:layout_above="@+id/editbox_laypou"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_alignParentBottom="true"
            android:weightSum="2"
            android:id="@+id/editbox_laypou">

            <EditText
                android:id="@+id/edit_text"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1.91"
                android:layout_marginLeft="10dp"
                android:textColor="@color/colorPrimaryDark"
                android:textColorHint="@color/colorPrimaryDark"
                android:textColorHighlight="@color/colorPrimary"
                android:hint="Send message"
                android:inputType="textMultiLine"
                android:maxLines="6"
                android:scrollbars="vertical">
            </EditText>

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/button_send"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginRight="3dp"
                android:layout_marginLeft="10dp"
                android:layout_marginBottom="16dp"
                android:layout_gravity="bottom|end"
                android:src="@drawable/ic_mic_white_24dp"/>

        </LinearLayout>
    </RelativeLayout>

答案 2 :(得分:0)

在清单

中添加此内容
android:windowSoftInputMode="adjustPan"
相关问题