Android协调器布局底栏隐藏在列表视图中

时间:2017-10-07 06:19:26

标签: android android-layout android-coordinatorlayout

底部按钮/某些视图会隐藏列表视图底部。

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

enter image description here

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

如果底栏显示,如何调整列表视图以滚动更多?

4 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:1)

我认为这将解决您的问题,

def sum_of_digits(num):
    """ Recursively add the digits of a positive integer until the sum
    becomes a single digit. Return the sum. """

    if num < 10:    # base case
        return num

    num_copy = num
    result = 0

    while num_copy > 0:
          remainder = num_copy % 10
          result += remainder
          num_copy //= 10

    return sum_of_digits(result)

print(sum_of_digits(12345678))

这是示例输出 enter image description here

注意: 您已添加 <?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"提供给nestedScrollView,并且无需使用recyclelerview填充。 我希望这能解决你的问题

答案 2 :(得分:0)

您应该使用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放在您的底栏上方。

答案 3 :(得分:0)

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