先上图,看看是不是你们想要的效果
看了一堆的TabLayout的详解,里面都是实现最基本的TabLayout+ViewPager(只能有文字,没有图片的那种),最后参考各种文档,终于写出来了,本人菜鸟一枚,代码会尽可能的详细,适合新手哦
如果你遇到了问题,可以先看一下文章的最后,是否和我的问题是一样的,可以快速解决哦
1.首先创建的是MainActivity.class的布局
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="2dp"
android:background="@color/gray2">
</View>
<android.support.design.widget.TabLayout
android:id="@+id/tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorHeight="0dp"
app:tabTextAppearance="@style/MyCustomTabTextAppearance"/>
2.写一个ViewPager的适配器,就叫ViewPagerAd