Giter Site home page Giter Site logo

sanyuzhang / circularviewpager Goto Github PK

View Code? Open in Web Editor NEW
41.0 4.0 9.0 309 KB

A Circular ViewPager for Android

License: MIT License

Java 100.00%
android android-library android-development android-ui android-app android-application android-studio android-sdk android-architecture androidstudio

circularviewpager's Introduction

CircularViewPager

A Circular ViewPager for Android

CircularViewPager actively supports android versions 4.0.3 (Ice Cream Sandwich) and above. That said, it works all the way down to 4.0.3 but is not actively tested or working perfectly.

  • Supports compileSdkVersion 28.0.2
  • Supports Gradle 4.4

Here is a short gif showing the functionality you get with this library:

Demo Gif

Goal

The goal of this project is to deliver a high performance circular viewpager.

Installing

Cloning First of all you will have to clone the library.

git clone [email protected]: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')
}

In the following dialog navigate to CircularViewPager which you cloned to your computer in the previous steps and select the build.gradle.

Maven Upcoming...

Gradle Upcoming...

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

CircularTabLayout tabLayout = (CircularTabLayout) findViewById(R.id.circular_tab);
CircularViewPager viewPager = (CircularViewPager) findViewById(R.id.circular_viewpager);
MyAdapter adapter = new MyAdapter(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 {

    List<Fragment> mFragments = 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!

Styling

You can apply your own theme to CircularTabLayout. Say you define a style called CircularTabTextAppearance in values/styles.xml:

<resources>
    <style name="CircularTabTextAppearance" parent="@style/TextAppearance.Design.Tab">
        <item name="android:textSize">@dimen/circular_tab_textsize</item>
        <item name="android:textColor">@color/colorPrimaryDark</item>
    </style>
</resources>

Then add CircularTabTextAppearance to CircularTabLayout:

<com.sanyuzhang.circular.viewpager.cvp.view.CircularTabLayout
    android:id="@+id/circular_tab"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabTextAppearance="@style/CircularTabTextAppearance"/>

Upcoming...

circularviewpager's People

Contributors

naufalfachrian avatar sanyuzhang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

circularviewpager's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.