Android 应用栏在灵活模式下滚动内容重叠 space

Android App bar scrolling with overlapping content in Flexible space

在我的布局中,我在灵活的应用栏中使用重叠内容滚动 space

我在水平滚动视图的嵌套滚动视图中有一个按钮列表,我想在向上滚动时停止顶部(操作栏下方)的水平可滚动按钮布局。如何实现,请帮忙?

这是我的布局结构:

<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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:ignore="RtlHardcoded">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        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/collapsing"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            app:contentScrim="?colorPrimary"
            app:expandedTitleMarginBottom="94dp"
            app:expandedTitleTextAppearance="@style/CollapsingTextAppearance.Inverse"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:title="@string/app_name">

            // conatins my header view

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

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:behavior_overlapTop="38dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/nestedScrollView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="none">

            <android.support.v7.widget.CardView
                android:id="@+id/cardview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="@dimen/margin"
                app:cardBackgroundColor="@color/white"
                android:focusableInTouchMode="false"
                android:focusable="false"
                app:cardCornerRadius="10dp"
                app:cardElevation="4dp"
                app:contentPaddingBottom="16dp"
                app:contentPaddingLeft="0dp"
                app:contentPaddingRight="0dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <HorizontalScrollView
                        android:id="@+id/horizontalSV"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:fillViewport="true"
                        android:scrollbarSize="2dp">

                        .... // conatins buttons

                        .... // conatins my list view view

                        </HorizontalScrollView>

                    </LinearLayout>


                </android.support.v7.widget.CardView>
        </android.support.v4.widget.NestedScrollView>
    </android.support.v4.widget.SwipeRefreshLayout>
    </android.support.design.widget.CoordinatorLayout>

参考随附的屏幕截图

将您的代码更改为 this.cut 您的代码并在卡片视图中使用滚动行为

<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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:ignore="RtlHardcoded">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        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/collapsing"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            app:contentScrim="?colorPrimary"
            app:expandedTitleMarginBottom="94dp"
            app:expandedTitleTextAppearance="@style/CollapsingTextAppearance.Inverse"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:title="@string/app_name">

            // conatins my header view

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

     <android.support.v7.widget.CardView
                android:id="@+id/cardview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="@dimen/margin"
                app:cardBackgroundColor="@color/white"
                android:focusableInTouchMode="false"
                android:focusable="false"
                app:cardCornerRadius="10dp"
                app:cardElevation="4dp"
                app:contentPaddingBottom="16dp"
                app:contentPaddingLeft="0dp"
                app:contentPaddingRight="0dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <HorizontalScrollView
                        android:id="@+id/horizontalSV"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:fillViewport="true"
                        android:scrollbarSize="2dp">

                        .... // conatins buttons

                        .... // conatins my list view view

                        </HorizontalScrollView>

                    </LinearLayout>

     <android.support.v4.widget.SwipeRefreshLayout
      android:id="@+id/swipeLayout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:behavior_overlapTop="38dp"
      app:layout_behavior="@string/appbar_scrolling_view_behavior">

      <android.support.v4.widget.NestedScrollView
       android:id="@+id/nestedScrollView"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:scrollbars="none">


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

                </android.support.v7.widget.CardView>


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