美文网首页Android知识Android技术知识Android开发
【开源分享】Android可循环Viewpager Lib源码及

【开源分享】Android可循环Viewpager Lib源码及

作者: 芋米EatWorld | 来源:发表于2017-10-05 13:51 被阅读0次

    以后会定期维护更新,求follow,求watch,谢谢大家。

    已经在Po主发布的3款APP中得到应用与可靠性验证,完美可用。

    具体效果如下GIF所示(左右滑动/tab点击皆可):

    如果想要用到自己的项目中,单独导入CircularViewPager模块即可。

    记得在gradle配置文件中compile module。

    Github地址

    Installing

    Cloning

    First of all you will have to clone the library.

    git clone git@github.com:sanyuzhang/CircularViewPager.git

    Now that you have the library you will have to import it into Android Studio. In Android Studio navigate the menus like this.

    File -> New -> Import Module -> CloneLocation/CircularViewPager/CircularViewPager

    Remember to add this to the build.gradle configuration of your app

    dependencies {

        ...

        compile project(':CircularViewPager')

    }

    Getting Started

    Base usage

    Ok lets start with your activities or fragments xml file. It might look something like this.

    <com.sanyuzhang.circular.viewpager.cvp.view.CircularTabLayout

    android:id="@+id/circular_tab"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:background="?attr/colorPrimary"

    app:scrollMillisecondsPerInch="70.0"

    app:tabIndicatorColor="@color/circular_tab_indicator_color"

    app:tabIndicatorHeight="@dimen/circular_tab_indicator_height"

    app:tabMarginEnd="@dimen/circular_tab_margin"

    app:tabMarginStart="@dimen/circular_tab_margin"

    app:tabSelectedTextColor="@color/circular_tab_selected_color"

    app:tabTextAppearance="@style/CircularTabTextAppearance"/>

    <com.sanyuzhang.circular.viewpager.cvp.view.CircularViewPager

    android:id="@+id/circular_viewpager"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:background="?attr/colorPrimary"/>

    Now in your activities onCreate() or your fragments onCreateView() you would want to do something like this

    CircularTabLayouttabLayout=(CircularTabLayout) findViewById(R.id.circular_tab);

    CircularViewPagerviewPager=(CircularViewPager) findViewById(R.id.circular_viewpager);

    MyAdapteradapter=newMyAdapter(getFragmentManager());

    viewPager.setFragmentAdapter(adapter, getFragmentManager());

    tabLayout.setupWithViewPager(viewPager);

    MyAdapter in the above example would look something like this, a list of fragments.

    class MyAdapter extends FragmentPagerAdapter {    ListmFragments = new ArrayList<>();

    public MyAdapter(FragmentManager fm) {

    super(fm);

    for (int position = 0; position < 5; position++) {

    mFragments.add(new SampleFragment());

    }

    }

    @Override

    public Fragment getItem(int position) {

    return mFragments.get(position);

    }

    @Override

    public int getCount() {

    return mFragments.size();

    }

    @Override

    public CharSequence getPageTitle(int position) {

    return String.format("Page %d", position);

    }

    }

    That's it! Look through the API docs below to get know about things to customize and if you have any problems getting started please open an issue as it probably means the getting started guide need some improvement!

    相关文章

      网友评论

        本文标题:【开源分享】Android可循环Viewpager Lib源码及

        本文链接:https://www.haomeiwen.com/subject/hwahyxtx.html