封装viewPager滑动

来源:互联网 发布:怎么登录商家淘宝店铺 编辑:程序博客网 时间:2024/06/05 03:47

easyViewPagerSlide

Compile 在项目中导入

compile 'com.micki:easyViewPagerSlide:1.3.1'

Usage 使用方法

ViewPagerSwitch    .getInstance() // must first    .init(this)    .addViewPager(viewPager)    .addTitles(textViews)    .addChildViews(views)    .setSelectedColor(R.color.colorAccent)    .setUnSelectedColor(R.color.colorPrimary)    .build(); // must last

In XML 布局配置

<LinearLayout     android:id="@+id/linearLayout_banner"     android:layout_width="match_parent"     android:layout_height="wrap_content">         <TextView             android:id="@+id/tv_first"             android:layout_width="match_parent"             android:layout_height="match_parent"             android:layout_weight="1.0"             android:gravity="center"             android:paddingBottom="10dp"             android:paddingTop="10dp"             android:text="first"             android:textColor="@color/selected_color"             android:textSize="15sp" />         <TextView             android:id="@+id/tv_second"             android:layout_width="match_parent"             android:layout_height="match_parent"             android:layout_weight="1.0"             android:gravity="center"             android:text="second"             android:textColor="@color/default_color"             android:textSize="15sp" />         <TextView             android:id="@+id/tv_third"             android:layout_width="match_parent"             android:layout_height="match_parent"             android:layout_weight="1.0"             android:gravity="center"             android:text="third"             android:textColor="@color/default_color"             android:textSize="15sp" /></LinearLayout><android.support.v4.view.ViewPager     android:id="@+id/viewPager"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_below="@+id/linearLayout_banner"     android:flipInterval="30"     android:persistentDrawingCache="animation"></android.support.v4.view.ViewPager>

In Activity or Fragment 调用

TextView textView1 = (TextView) findViewById(R.id.tv_first);TextView textView2 = (TextView) findViewById(R.id.tv_second);TextView textView3 = (TextView) findViewById(R.id.tv_third);// tabsTextView[] tabs = {textView1, textView2, textView3};// child viewsView view1 = View.inflate(this, R.layout.view_1, null);View view2 = View.inflate(this, R.layout.view_2, null);View view3 = View.inflate(this, R.layout.view_3, null);List<View> views = new ArrayList<>();    views.add(view1);    views.add(view2);    views.add(view3);ViewPagerSwitch    .getInstance() // must first    .init(this)    .addViewPager(viewPager)    .addTitles(tabs)    .addChildViews(views)    .setSelectedColor(R.color.colorAccent)    .setUnSelectedColor(R.color.colorPrimary)    .build(); // must last

最后附上github地址,欢迎star、issues. https://github.com/micki-zhou/easyViewPagerSlide

0 0