滚动两个子回收器视图,然后将第二个回收器视图的顶部固定在顶部并滚动其内容

时间:2020-05-16 16:37:50

标签: android xml android-recyclerview scrollview android-constraintlayout

我有以下类型的布局设置。 ConstraintLayout的第一个孩子是回收者视图,第二个孩子是SwipeRefreshLayout,其中有另一个回收者视图。

我已经实现了布局,一切都很好。当前,底部回收器视图滚动,并且其项目在容器下方滑动。第一个回收站视图根本不滚动。可能是因为高度设置为wrap_content。但这是我想保留的东西 Layout

我的布局的组件树是:

enter image description here

我要实现的是: 1.当检测到滚动时,将两个回收站视图向上滚动 2.要么继续向上滚动,要么第二个回收站视图固定在顶部,并且只滚动其内容。

布局代码为:

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

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar_main"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        android:background="@color/colorPrimary"
        android:theme="@style/ToolbarThemeMain">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                style="@style/Bold.Large"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:gravity="center"
                android:paddingTop="@dimen/dimen_4dp"
                android:text="@string/explore"
                android:textColor="@color/colorWhite"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.appcompat.widget.Toolbar>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rv_explore_category_items"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/dimen_16dp"
            android:layout_marginTop="@dimen/dimen_16dp"
            android:layout_marginEnd="@dimen/dimen_16dp"
            android:overScrollMode="never"
            android:visibility="@{viewModel.categoriesListIsEmpty ? View.GONE: View.VISIBLE}"
            app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
            app:layout_constraintTop_toTopOf="parent"
            app:spanCount="2"
            tools:itemCount="6"
            tools:listitem="@layout/item_explore_categories" />


        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginTop="@dimen/dimen_32dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/rv_explore_category_items"
            app:onRefreshListener="@{() -> viewModel.onRefresh()}"
            app:refreshing="@{viewModel.isRefreshing}">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/rv_explore_feeds"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:visibility="@{viewModel.feedListIsEmpty ? View.GONE: View.VISIBLE}" />


        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

        <TextView
            style="@style/MyTextAppearanceSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/txt_err_no_public_feed"
            android:visibility="@{viewModel.feedListIsEmpty ? View.VISIBLE: View.GONE}"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@id/rv_explore_category_items" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>

感谢您抽出宝贵时间阅读本文档。

0 个答案:

没有答案
相关问题