如何在滚动时将Recyclerview推到下面的AppbarLayout下方(隐藏)

时间:2019-07-19 23:14:20

标签: java android android-recyclerview android-coordinatorlayout android-appbarlayout

我想实现AppBarLayout + Recyclerview scrollingviewbehavior效果不常见的功能。

我想让Recyclerview与AppBarLayout一起移动,并在用户滚动时在AppBarLayout后面。我需要它确实位于AppBarlayout的后面,因为AppbarLayout的背景将是半透明的,以便可见recyclerview。

我不知道该怎么做。

我确实尝试了ScrollViewBehavior的多个变体。 我也尝试过将SwipeRefreshlayout topMaring设置为负值,并在滚动过程中更改此值。从给定的“垂直滚动偏移量”的AppBarLayout.addOnOffsetChangedListener提供的值。结果是swipeRefreshLayout在滚动期间和在AppBarLayout后面时闪烁。

请帮助我。我没有其他选择了。

<androidx.coordinatorlayout.widget.CoordinatorLayout
        android:id="@+id/clRootMain"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="false"
        android:background="@color/backgroundGray">

        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
            android:id="@+id/srlSwipeRefresh"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"
            android:isScrollContainer="true"
            app:layout_behavior=".Util.View.ScrollingViewOverlapBehavior">

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

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/rvList"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:clipChildren="false"
                    android:divider="@android:color/transparent"
                    android:dividerHeight="@dimen/dp5"
                    android:drawSelectorOnTop="true"
                    android:fadeScrollbars="true"
                    android:fadingEdge="none"
                    android:fadingEdgeLength="@dimen/dp0"
                    android:gravity="center"
                    android:isScrollContainer="true"
                    android:nestedScrollingEnabled="true"
                    android:overScrollMode="never"
                    android:paddingLeft="@dimen/list_margin"
                    android:paddingRight="@dimen/list_margin"
                    android:scrollbarAlwaysDrawVerticalTrack="true"
                    android:scrollbarSize="@dimen/dp4"
                    android:scrollbarStyle="outsideOverlay"
                    android:scrollbars="vertical"
                    android:smoothScrollbar="false"
                    app:fastScrollEnabled="true"
                    app:fastScrollHorizontalThumbDrawable="@drawable/scrollbar_draggable"
                    app:fastScrollHorizontalTrackDrawable="@drawable/scrollbar_track_line"
                    app:fastScrollVerticalThumbDrawable="@drawable/scrollbar_draggable"
                    app:fastScrollVerticalTrackDrawable="@drawable/scrollbar_track_line" />

                <TextView
                    android:id="@+id/tvEmptyListText"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="@dimen/dp20"
                    android:layout_marginTop="@dimen/dp10"
                    android:layout_marginRight="@dimen/dp20"
                    android:alpha="0.5"
                    android:gravity="center"
                    android:text="@string/category_product_list_empty"
                    android:textColor="@color/textGreyDark"
                    android:visibility="gone" />

            </LinearLayout>

        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>


        <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/ablMain"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#80ffffff"
            android:fitsSystemWindows="true"
            android:orientation="vertical"
            app:liftOnScroll="false">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent"
                android:orientation="vertical"
                app:layout_scrollFlags="scroll|enterAlwaysCollapsed|exitUntilCollapsed">

                <LinearLayout
                    android:id="@+id/llOpenOrderListContainer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:visibility="gone">


                    <TextView
                        android:id="@+id/tvOpenOrdersTitle"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="@dimen/dp10"
                        android:layout_marginTop="@dimen/dp15"
                        android:alpha="0.6"
                        android:clickable="false"
                        android:gravity="center|left"
                        android:singleLine="true"
                        android:text="@string/current_orders_title"
                        android:textAllCaps="true"
                        android:textAppearance="@style/TextAppearance.AppCompat.Body2"
                        android:textColor="@color/textColor"
                        android:textSize="@dimen/sp10"
                        android:textStyle="normal" />


                    <androidx.viewpager.widget.ViewPager
                        android:id="@+id/vpOpenOrderList"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/dp75"
                        android:background="@android:color/transparent"
                        android:visibility="visible" />
                </LinearLayout>

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

                    <RelativeLayout
                        android:id="@+id/rlTopContainer"
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:background="@android:color/white"
                        app:layout_constraintDimensionRatio="H,16:9"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent">


                        <androidx.viewpager.widget.ViewPager
                            android:id="@+id/vpBannerPager"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="@android:color/transparent" />

                        <RelativeLayout
                            android:id="@+id/rlControlContainer"
                            android:layout_width="@dimen/dp100"
                            android:layout_height="@dimen/dp30"
                            android:layout_alignParentBottom="true"
                            android:layout_centerHorizontal="true"
                            android:layout_marginBottom="@dimen/dp15"
                            android:background="@android:color/transparent">

                            <com.google.android.material.tabs.TabLayout
                                android:id="@+id/tlBannerDots"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_centerInParent="true"
                                app:tabBackground="@drawable/tab_selector_images"
                                app:tabGravity="center"
                                app:tabIndicatorHeight="0dp"
                                app:tabMinWidth="@dimen/dp3"
                                app:tabMode="fixed" />

                        </RelativeLayout>

                        <ImageView
                            android:id="@+id/ivHalfCircleBackgroundWithStroke"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_alignParentBottom="true"
                            android:layout_marginTop="@dimen/dp50"
                            android:scaleType="fitXY"
                            app:srcCompat="@drawable/ic_bottom_arc"

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


            </LinearLayout>


            <RelativeLayout
                android:id="@+id/rlCategoryContainer"
                android:layout_width="match_parent"
                android:layout_height="@dimen/dp75"
                android:background="@android:color/transparent">

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/rvCategoryList"
                    android:layout_width="wrap_content"
                    android:layout_height="@dimen/dp70"
                    android:layout_above="@+id/llSeparatorLine"
                    android:layout_centerHorizontal="true"
                    android:clipChildren="false"
                    android:divider="@android:color/white"
                    android:dividerHeight="@dimen/dp10"
                    android:drawSelectorOnTop="true"
                    android:fadeScrollbars="true"
                    android:fastScrollEnabled="false"
                    android:gravity="center"
                    android:isScrollContainer="true"
                    android:nestedScrollingEnabled="true"
                    android:overScrollMode="never"
                    android:scrollIndicators="none"
                    android:scrollbars="none" />

                <LinearLayout
                    android:id="@+id/llSeparatorLine"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/dp1"
                    android:layout_alignParentBottom="true"
                    android:background="@drawable/grey_line_with_fading_edges_light"
                    android:orientation="horizontal" />

            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/rlBottomDownArcContainer"
                android:layout_width="match_parent"
                android:layout_height="@dimen/dp40"

                android:background="@android:color/transparent">


                <TextView
                    android:id="@+id/tvSectionName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:background="@android:color/transparent"
                    android:clickable="false"
                    android:gravity="center_horizontal|top"
                    android:singleLine="true"
                    android:text="KWIATY"
                    android:textAllCaps="true"
                    android:textAppearance="@style/TextAppearance.AppCompat.Body1"
                    android:textColor="@color/textGrey"
                    android:textSize="@dimen/sp12"
                    android:textStyle="bold" />

            </RelativeLayout>


        </com.google.android.material.appbar.AppBarLayout>


        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fabFilter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_marginLeft="@dimen/dp5"
            android:layout_marginTop="@dimen/dp5"
            android:layout_marginRight="@dimen/dp10"
            android:layout_marginBottom="@dimen/dp10"
            android:elevation="@dimen/dp4"
            android:stateListAnimator="@animator/lift_on_touch"
            android:visibility="visible"
            app:backgroundTint="@android:color/white"
            app:borderWidth="0dp"
            app:elevation="4dp"
            app:fabSize="normal"
            app:rippleColor="@color/colorAccent"
            app:srcCompat="@drawable/ic_icon_filtr_black" />

        <!--</RelativeLayout>-->
    </androidx.coordinatorlayout.widget.CoordinatorLayout>
public class ScrollingViewOverlapBehavior extends AppBarLayout.ScrollingViewBehavior {

    public ScrollingViewOverlapBehavior() {
        super();
    }

    public ScrollingViewOverlapBehavior(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent, View child,
                                          View dependency) {
        super.onDependentViewChanged(parent, child, dependency);

        child.setTranslationY(dependency.getY());

        return false;
    }
}

这是我到目前为止所取得的成就,但它在底部留有空间。我在自定义ScrollingViewBehavior(ScrollingViewOverlapBehavior)上使用setTranslationY。

https://drive.google.com/open?id=12Ri87BGKmAmwNq_rC-wpmCcYZyansmGl

0 个答案:

没有答案