Android开发Viewpager2和SlidingTabLayout结合使用

Android开发Viewpager2和SlidingTabLayout结合使用
第一步:xml
<androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/cl_select_edu_auth"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintTop_toBottomOf="@id/only_iv_sesame_desc"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginTop="@dimen/dp_30"
        android:background="@color/white"
        android:layout_marginLeft="@dimen/d40px"
        android:layout_marginRight="@dimen/d40px">

        <com.flyco.tablayout.SlidingTabLayout
            android:id="@+id/stl_edu_auth"
            android:layout_width="match_parent"
            android:layout_height="@dimen/dp_40"
            app:tl_indicator_color="@color/c_main"
            app:tl_indicator_height="@dimen/dp_4"
            app:tl_indicator_width="@dimen/dp_16"
            app:tl_indicator_corner_radius="@dimen/dp_2"
            app:tl_tab_space_equal="true"
            app:tl_textsize="16sp"
            app:tl_textSelectColor="@color/black"
            app:tl_textUnselectColor="@color/c_aa"
            app:tl_textSelectSize="18sp"
            app:tl_textBold="BOTH"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            android:layout_marginTop="@dimen/dp_12"/>



        <androidx.viewpager2.widget.ViewPager2
            android:id="@+id/vp2_edu_auth"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_constraintTop_toBottomOf="@id/stl_edu_auth"
            app:layout_constraintBottom_toBottomOf="parent"
            android:layout_marginBottom="@dimen/dp_24"
            />


    </androidx.constraintlayout.widget.ConstraintLayout>
第二步:代码使用
 vp2_edu_auth.adapter = object : FragmentStateAdapter(this){
            override fun getItemCount(): Int {
                return 2
            }
            override fun createFragment(position: Int): Fragment {
                return OnlyEduAuthTypeFragment.newInstance(position )
            }
        }
        stl_edu_auth.setViewPager2(vp2_edu_auth , arrayListOf<String>(getString(R.string.chinese_mainland),getString(
            R.string.international)))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

893151960

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值