android tab切换 悬浮选择器

本文基于 Android Tablayout、CoordinatorLayout、AppBarLayout的使用 实现悬停 页面切换_徐玮的博客-CSDN博客

做一些特殊说明


        <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <com.google.android.material.appbar.AppBarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

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

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="100dp"
                        android:src="@drawable/ic_launcher" />


                </LinearLayout>


                <com.google.android.material.tabs.TabLayout
                    android:id="@+id/tablayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="#fff"
                    app:tabBackground="@color/transparent"
                    app:tabIndicatorColor="#07D97F"
                    app:tabIndicatorFullWidth="false"
                    app:tabMode="scrollable"
                    app:tabRippleColor="@color/transparent"
                    app:tabSelectedTextColor="#333"
                    app:tabTextColor="#333" />


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


            <androidx.core.widget.NestedScrollView
                android:id="@+id/nest"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fadingEdge="none"
                android:overScrollMode="never"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/recyclerview"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/appYellow">


                </androidx.recyclerview.widget.RecyclerView>

            </androidx.core.widget.NestedScrollView>



        </androidx.coordinatorlayout.widget.CoordinatorLayout>

父布局 CoordinatorLayout AppBarLayout 是必须要的

可见的view中

主要是这几个属性在控制  app:layout_scrollFlags="scroll" 控制是否可以划出屏幕 

LinearLayout 添加了 则它可以滚出屏幕 同层次下的 TabLayout  没有添加 则当滚动时 它会停留在顶部
NestedScrollView 添加 代码中的属性后 当滚动该视图中的view时 会传递到CoordinatorLayout 中 可以看起来作为一个整体滚动       如下图的触摸黄色区域 滚动向上时 选择器也会跟着滚动 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值