美文网首页
Android CoordinatorLayout,AppBar

Android CoordinatorLayout,AppBar

作者: 捡豆豆 | 来源:发表于2020-03-11 15:59 被阅读0次

问题发现:

CoordinatorLayout,AppBarLayout嵌套 recycleview快速滑动之后 会有近几秒秒的停滞,状态还是SCROLL_STATE_SETTLING 之后状态才变成 SCROLL_STATE_IDLE
这个过程中再滑动页面会出现页面滑动错乱的现象(support库版本从26.0.0)
我这边的xml代码如下
<android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:elevation="0dp"
            app:layout_behavior="com.lemiao.funbidding.widget.WhlBehavior"
            android:fitsSystemWindows="true">

            <TextView
                android:id="@+id/scroll_status"
                android:layout_width="match_parent"
                android:background="@color/white"
                android:layout_height="0dp"
                app:layout_scrollFlags="scroll"/>

            <com.lemiao.funbidding.widget.bgabanner.BGABanner
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:id="@+id/play_detail_head_banner"
                android:background="@color/white"
                app:banner_pageChangeDuration="1000"
                app:banner_pointAutoPlayAble="true"
                app:banner_pointAutoPlayInterval="6000"
                app:banner_pointContainerBackground="@android:color/transparent"
                app:banner_pointDrawable="@android:color/transparent"
                android:minHeight="44dp"
                android:visibility="visible"
                app:banner_isNumberIndicator="true"
                app:banner_numberIndicatorBackground="@drawable/shape_radius_50black_8"
                app:banner_transitionEffect="defaultEffect"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"/>

            <RelativeLayout
                android:background="@color/white"
                android:layout_width="match_parent"
                android:layout_height="57dp">

                <LinearLayout
                    android:id="@+id/play_detail_head_current_price_ll"
                    android:gravity="bottom"
                    android:layout_marginTop="3dp"
                    android:layout_width="match_parent"
                    android:layout_height="28.5dp">

                    <TextView
                        android:id="@+id/play_detail_head_current_price_label"
                        android:layout_marginLeft="15dp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="当前价"
                        android:textSize="12sp"
                        android:textColor="@color/text_color_1"/>

                    <com.lemiao.funbidding.widget.MediumBoldTextView
                        android:id="@+id/play_detail_head_current_price"
                        android:layout_marginLeft="3dp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="12sp"
                        android:textColor="@color/common_red_2"/>

                </LinearLayout>

                <LinearLayout
                    android:layout_below="@+id/play_detail_head_current_price_ll"
                    android:layout_width="wrap_content"
                    android:gravity="top"
                    android:paddingTop="1.5dp"
                    android:layout_height="28.5dp">

                    <TextView
                        android:layout_marginLeft="15dp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="市场价"
                        android:textSize="12sp"
                        android:textColor="@color/text_color_3"/>


                    <com.lemiao.funbidding.widget.MediumBoldTextView
                        android:id="@+id/play_detail_head_price"
                        android:layout_marginLeft="2dp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="12sp"
                        android:textColor="@color/text_color_3"/>
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/play_detail_head_status_ll"
                    android:layout_alignParentRight="true"
                    android:layout_width="140dp"
                    android:gravity="center"
                    android:background="@drawable/shape_rectangle_red"
                    android:layout_height="match_parent">

                    <TextView
                        android:id="@+id/play_detail_head_status_tv"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="结束仅剩"
                        android:textSize="12sp"
                        android:textColor="@color/white"/>

                    <com.lemiao.funbidding.widget.EasyCountDownTextureView
                        android:id="@+id/play_detail_head_countdown_time"
                        android:layout_marginLeft="5dp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        app:easyCountHour="0"
                        app:easyCountMinute="0"
                        app:easyCountSecond="0"
                        app:easyCountColonColor="@color/white"
                        app:easyCountBackgroundColor="#F58D91"/>

                </LinearLayout>

                <LinearLayout
                    android:id="@+id/play_detail_head_status_ll2"
                    android:layout_alignParentRight="true"
                    android:layout_width="140dp"
                    android:gravity="center"
                    android:visibility="gone"
                    android:orientation="vertical"
                    android:background="@drawable/shape_rectangle_red"
                    android:layout_height="match_parent">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="即将开拍"
                        android:textSize="12sp"
                        android:alpha="0.5"
                        android:textColor="@color/white"/>

                    <TextView
                        android:id="@+id/play_detail_head_countdown_time2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="16sp"
                        android:text="12-26 13:00"
                        android:textColor="@color/white"/>

                </LinearLayout>

            </RelativeLayout>

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

        <android.support.v7.widget.RecyclerView
            android:id="@+id/content_recycle_view"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:overScrollMode="always"
            android:scrollbars="none"/>

    </android.support.design.widget.CoordinatorLayout>
虽然滑动停止了,但其实状态还是滑动中。当然这个时间不是固定的,完全取决于你的手速。你滑动的越快这个时间越长,所以从RecyclerView惯性滑动来入手
问题原因:RecyclerView 在 fling 过程中并没有通知AppBarLayout,所以在fling结束之后,AppBarLayout不知道当前RecyclerView的滑动到的位置,所以导致了这个滑动被打断的问题。其实相关的滑动卡顿问题,病因都是这里。
最终查找当前最新的28.0.0-rc02版本,官方针对这一问题做了修改
解决方案:design 升级到28.0.0 以上的问题会得到解决(推荐)

相关文章

网友评论

      本文标题:Android CoordinatorLayout,AppBar

      本文链接:https://www.haomeiwen.com/subject/gqvcjhtx.html