簡體   English   中英

Android Coordinator Layout底部欄隱藏在列表視圖中

[英]Android Coordinator Layout bottom bar hide inside the list view

底部按鈕/某些視圖隱藏了列表視圖的底部。

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

在此處輸入圖片說明

我將根據條件使底視圖可見和不可見。

如果底部欄可見,如何調整列表視圖以滾動更多內容?

您可以在android:clipToPadding = "false"添加android:clipToPadding = "false" 當顯示底部按鈕時,您可以為NestedScrollview動態添加底部填充,其值等於底部按鈕的高度。

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

我認為這可以解決您的問題,

 <?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" 。相反,您可以按照我的解決方案進行操作,只需將android:fillViewport="true"賦予nestedScrollView而無需填充需要用到recyclerview。 我希望這能解決您的問題

您應該通過如下使用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>

根據您的方面,它將scrollview放在底部欄的頂部。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM