zhpanvip/viewpagerindicator

Animated selection feature

theoyuncu8 opened this issue · 3 comments

I wanted to use this library without viewpager/viewpage2 in my project, but for some reason I couldn't choose. Even though I tried the setCurrentPosition and onPageSelected methods, nothing happened.. then I added a viewpager to my project and it still didn't work.

I solved the problem by notifying after setCurrentPosition. I'm not sure if this is the correct solution?

I want an animated transition when selection is made, can you add such a feature?
For example, let the worm animation switch at 200 ms, can we adjust this time?
<com.zhpan.indicator.IndicatorView android:id="@+id/indicatorView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_margin="9dp" android:gravity="center" android:orientation="horizontal" app:vpi_orientation="horizontal" app:vpi_slide_mode="worm" app:vpi_slider_checked_color="@color/colorPalette4" app:vpi_slider_normal_color="@color/defaultColor3" app:vpi_style="round_rect" />

    `indicatorView.setPageSize(11);
    indicatorView.setCurrentPosition(0);
    indicatorView.onPageSelected(0);
    indicatorView.notifyDataChanged();`
    
    `public void moveNext(){
     indicatorView.setCurrentPosition(indicatorView.getCurrentPosition()+1);
      indicatorView.notifyDataChanged();
    }
    
    public void movePrev(){
     indicatorView.setCurrentPosition(indicatorView.getCurrentPosition()-1);
      indicatorView.notifyDataChanged();
    }
    `

The slider animattion is only used to ViewPager or ViewPager2, It's can't support other views.unless you can caculate the position/positionOffset and positionOffsetPixels when the view page scrolling,just like the ViewPager/ViewPager2
page scrolling.

and then you can do like the following code:

    override fun onPageScrolled(
      position: Int,
      positionOffset: Float,
      positionOffsetPixels: Int
    ) {
      viewPagerIndicator.onPageScrolled(position, positionOffset, positionOffsetPixels)
    }

You need use onPageSelected instead of setCurrentPosition.

Currently, animation transition cannot be supported after the position selected.