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

thanhniencung avatar waylife 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

infiniteviewpager's Issues

CirclePageIndicator at the last item go to empty before jump to the first item

Hi,

Great library,

I setup the demo sample, and I notice that for LinePageIndicator when transition from first to last or last to first it didn't jump to the empty spot.

However, for the CirclePageIndicator when transition from first to last or last to first it jumps to the empty spot first before move to fist or last.

Is there anyway we can make it smooth without go to empty spot for CirclePageIndicator?

Thank

Unable to view last page from first page

Unable to view last page from first page if the viewpager is not scrolled even once. if the view pager is scrolled once then we are able to view the last page. also can be seen the sample.

Circle Indicator issue

I am using infinite ViewPager inside the fragment that point of time its working fine but the issue come when I am replacing with the another fragment and come back then getting number of circular line indicator became double number (like If first time showing 3 dots after replacing fragment and comeback getting 6 dots of circle) (This issue cumming with both indicator)

infiniteViewpager scroll is not working inside viewpager

I have viewpager with 4 tabs and in one of the tab there is infiniteViewpager. And infiniteViewpager is also there in one of the Fragment of viewpager.

When i user infiniteviewpager in view where there is no viewpager as parent it works fine. But when viewpager is in parent view then it doesn't scroll and resist in scrolling observed.

java.lang.ArithmeticException: divide by zero(getFakeFromReal 有可能会为 0)

_FakePositionHelper_ 里有一个方法 _getFakeFromReal_

public static int getFakeFromReal(InfiniteViewPager viewPager, int real) {
    int realAdapterSize = viewPager.getAdapterSize() / MULTIPLIER;
    return real % realAdapterSize;
}

在 ViewPager 嵌套时,切换过快, _realAdapterSize_ 有可能为 0 ,应用会 crash 。报错信息为

java.lang.ArithmeticException: divide by zero

手指按下,再抬起,不会自动滚动

// 代码修改成如下就能满足需求
@OverRide
public boolean onInterceptTouchEvent(MotionEvent ev) {
// to solve conflict with parent ViewGroup
getParent().requestDisallowInterceptTouchEvent(true);
if (this.mAutoScroll || this.mTouchedWhenAutoScroll) {
int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
this.mTouchedWhenAutoScroll = true;
stopAutoScroll();
break;
case MotionEvent.ACTION_UP:// 手指抬起后,继续滑动
this.mTouchedWhenAutoScroll = false;
startAutoScroll();
break;
}
}
return super.onInterceptTouchEvent(ev);
}

Unable to vertical scroll

When added as header in a recycler view, unable to vertical scroll when touched on the viewpager. and when trying to scroll through the viewpager when autoscrolling it stutters and doesnt change the page.

position doesn't match

hi,when i set onClickListener for imageview in viewpager item ,but the position doesn't match

请问如何禁止无限滑动?

看了一下源代码..没太看懂实现思路
请问如何设置滑动到最后一个后禁止再右滑回到第一个。
谢谢。

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.