Android Coordinator Layout 底栏隐藏在列表视图中

Android Coordinator Layout bottom bar hide inside the list view

底部 button/some 视图隐藏列表视图底部。

  <android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout


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

         <android.support.v4.widget.NestedScrollView 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:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                tools:context="example.design.activities.DetailsActivity"
                android:background="@color/grey">

                <android.support.v7.widget.RecyclerView
                    android:paddingTop="80dp"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>


            </android.support.v4.widget.NestedScrollView>


        <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="bottom"
                android:gravity="bottom">

                <!-- Add to cart button -->
                <android.support.v7.widget.AppCompatButton
                    android:id="@+id/ssssss"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:padding="20dp"
                    android:text="ADD TO CART"
                    android:backgroundTint="@color/colorPrimary"
                    android:textColor="@color/white"
                    android:layout_alignParentBottom="true"
                    android:visibility="visible" />

            </RelativeLayout>

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

我会根据条件使底部视图可见和不可见。

如果底栏可见,我如何调整我的列表视图以滚动更多?

您可以在 NestedScrollView 中添加 android:clipToPadding = "false"。 当您显示底部按钮时,您可以为 NestedScrollview 动态添加底部填充,其值等于底部按钮的高度。

nestedScrollView.setPadding(yourPadding, yourPadding,yourPadding, btn.getMeasuredHeight())

您应该使用 layout_anchor 更改 NestedScrollView,如下所示。

<android.support.v4.widget.NestedScrollView 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:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="example.design.activities.DetailsActivity"
    android:background="@color/colorPrimary"
    app:layout_anchor="@+id/relative_view"
    app:layout_anchorGravity="top">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:paddingTop="80dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>


</android.support.v4.widget.NestedScrollView>

它根据您的外观将滚动视图放在底部栏的顶部。

我想这会解决你的问题,

 <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:fillViewport="true"
        android:background="@android:color/darker_gray">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_alignParentTop="true"
                android:layout_height="match_parent"
                android:layout_above="@+id/ssssss"/>

            <!-- Add to cart button -->
            <android.support.v7.widget.AppCompatButton
                android:id="@+id/ssssss"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="20dp"
                android:text="ADD TO CART"
                android:layout_alignParentBottom="true"
                android:backgroundTint="@color/colorPrimary"
                android:textColor="@android:color/white"

                android:visibility="visible" />

        </RelativeLayout>


    </android.support.v4.widget.NestedScrollView>




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

这是示例输出

注意: 您已经添加了 android:fitsSystemWindows="true",因此您需要 android:paddingTop="80dp" 在您的回收站 view.Instead 中,您可以按照我的解决方案进行操作,只需将 android:fillViewport="true" 提供给 nestedScrollView 并且 recyclerview 不需要填充。 我希望这能解决您的问题

<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">


    <android.support.v4.widget.NestedScrollView 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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#EAEAEA"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context="example.design.activities.DetailsActivity">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <!-- Add to cart button -->
            <android.support.v7.widget.AppCompatButton
                android:id="@+id/ssssss"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:backgroundTint="@color/colorPrimary"
                android:padding="20dp"
                android:text="ADD TO CART"
                android:textColor="#FFFFFF"
                android:visibility="visible" />

            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/ssssss"
                android:layout_alignParentTop="true"
                android:paddingTop="80dp" />
        </RelativeLayout>

    </android.support.v4.widget.NestedScrollView>


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