GitHub地址:https://github.com/heavenxue/SlidingTitleBar
依赖
compile 'com.lixue.aibei:slidingtitlebarlib:1.0'
布局使用
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.myapplication.MainActivity">
<com.lixue.aibei.slidingtitlebarlib.SlidingTabScript
android:id="@+id/slidingtag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="false"
app:allowWidthFull="true"
app:disableTensileSlidingBlock="false"
app:disableViewPager="false"
app:slidingBlock="@mipmap/ic_launcher"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="0dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我叫"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我叫"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我叫"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我叫"/>
</LinearLayout>
</com.lixue.aibei.slidingtitlebarlib.SlidingTabScript>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/viewpager">
</android.support.v4.view.ViewPager>
</LinearLayout>
Main代码
package com.example.myapplication;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import com.lixue.aibei.slidingtitlebarlib.SlidingTabScript;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private SlidingTabScript slidingtag;
private ViewPager viewpager;
ArrayList<Fragment> arrayList=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
slidingtag = (SlidingTabScript) findViewById(R.id.slidingtag);
viewpager = (ViewPager) findViewById(R.id.viewpager);
arrayList.add(new BlankFragment());
arrayList.add(new BlankFragment());
arrayList.add(new BlankFragment());
arrayList.add(new BlankFragment());
viewpager.setAdapter(new Myfragment(getSupportFragmentManager()));
slidingtag.setViewPager(viewpager);
}
class Myfragment extends FragmentPagerAdapter{
public Myfragment(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return arrayList.get(position);
}
@Override
public int getCount() {
return arrayList.size();
}
}
}