Git Product home page Git Product logo

infiniteviewpager's Introduction

InfiniteViewpager

https://github.com/waylife/InfiniteViewPager

δΈ­ζ–‡ English

Function

  • Automatically scroll to next page
  • Smoothly scrolls from the end page to the first page,so does first to end.
  • View reuse support, no worrying about OOM
  • With indicator support(Modification of ViewpagerIncicator)
  • Fluid when invoking ViewPager.setCurrentItem(), better than the common solution

Preview

Sample demo

Usage

Almost the same as the viewpager. Below are some steps.

define in xml layout

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="200dp">

            <com.zanlabs.widget.infiniteviewpager.InfiniteViewPager
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="fill_parent"
                android:visibility="visible" />

            <com.zanlabs.widget.infiniteviewpager.indicator.LinePageIndicator
                android:id="@+id/indicator"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                app:fillColor="#e3ffc7"
                app:pageColor="#5fff65" />
        </RelativeLayout>

implement the InfinitePagerAdapter

Similar as the implement of BaseAdapter. You need to overide the getView and getItemCount(not getCount) mehtod.

    @Override
     public View getView(int position, View view, ViewGroup container) {
         ViewHolder holder;
         if (view != null) {
             holder = (ViewHolder) view.getTag();
         } else {
             view = mInflater.inflate(R.layout.item_infinite_viewpager, container, false);
             holder = new ViewHolder(view);
             view.setTag(holder);
         }
         PagerItem item = mList.get(position);
         holder.position = position;
         holder.name.setText(item.getName());
         holder.description.setText(item.getDesc()+"position:"+position);
         Picasso.with(mContext).load(item.getImageUrl()).placeholder(R.mipmap.bg_loding_horizontal).into(holder.image);
         return view;
     }


     @Override
     public int getItemCount() {
         return mList==null?0:mList.size();
     }

setup in activity or fragment.

   @Override
    protected void onCreate(Bundle savedInstanceState) {
        //
        MockPagerAdapter pagerAdapter = new MockPagerAdapter(this);
        pagerAdapter.setDataList(MockDataGenerator.getViewPagerData());
        mViewPager.setAdapter(pagerAdapter);
        mViewPager.setAutoScrollTime(5000);
        mViewPager.startAutoScroll();
        mLineIndicator.setViewPager(mViewPager);
        //
      }

    @Override
    public void onStart() {
        super.onStart();
        if (mViewPager != null)
            mViewPager.startAutoScroll();
    }

    @Override
    public void onStop() {
        if (mViewPager != null)
            mViewPager.stopAutoScroll();
        super.onStop();
    }

More You can refer to the sample project.

Thanks to

License

The MIT License.

infiniteviewpager's People

Contributors

waylife avatar thanhniencung avatar

Stargazers

Mosk avatar

Watchers

James Cloos avatar  avatar

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.