Android 应用栏在灵活空间中滚动内容重叠

标签 android android-collapsingtoolbarlayout android-nestedscrollview

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

我在水平 ScrollView 的嵌套 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: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>

请参阅随附的屏幕截图以供引用。

enter image description here

最佳答案

将你的代码更改为this.cut你的代码并在cardview中使用滚动行为

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

关于Android 应用栏在灵活空间中滚动内容重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49853346/

相关文章:

c# - 如何平滑路径图的WPF线段

android - 在 android tablayout 中禁用选项卡之间的滑动

android - CoordinatorLayout 内的 Viewpager 不滚动折叠工具栏

java - EditText 在 NestedScrollView 内不可滚动

android - 如何在 NestedScrollView 中使用 RecyclerView

android - NestedScrollView 中的 RecyclerView 在加载大量数据时花费太多时间

java - 如何使用 ConnectionService 获取 Call UI Presentation

android - 折叠工具栏显示额外的间距

android - CollapsingToolbarLayout 不随 ScrollView 滚动

android - Android问题中的AnimationDrawable