封装viewPager滑动

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);

// tabs
TextView[] tabs = {textView1, textView2, textView3};

// child views
View 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值