非常简单的实现Tab标签,用Viewpager+Fragment实现的。
有两个关键点:
1、Activity集成FragmentActivity
2、重写FragmentPagerAdapter的适配器
实现:
xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical">
<!--头部的便签 优点:样式随意定制-->
<LinearLayout
android:background="#FFD9EC"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:onClick="firstClick"
android:id="@+id/first"
style="@style/topTextStyle"
android:text="1" />
<TextView
android:id&#