Dynamically change count of PagerIndicator in ViewPager or PagerAdapter
Asked Answered
Q

1

6

enter image description here

What effect I want to have is :

  1. number of Bottom Circle indicator must be half of page count when page width is half.

  2. number of Bottom Circle indicator must be as much as page count when page width is full.

also, there is an another request:

  1. can i scroll two pages in single scroll when page width is half?
  2. and scroll only one page in single scroll when page width is full?

page width is acquired by PagerAdapter#getPageWidth()

can anyone give the perfect solution for this? without making two layout files or two adapters?

Here's the whole source code that I have developed to achieve this GIF based activity.

Question Improvement will be accepted.

https://github.com/raghavsatyadev/DemoPort

Quezada answered 1/9, 2016 at 8:33 Comment(4)
i do not understand, you meam scrolling? left right?Laritalariviere
yes scrolling also. when width is half I want to scroll two pages at the same time (on a single swipe)Quezada
Would you please answer my question.In half Width Mode, If you scroll right or left, both items would change or no just one of them would change ? what is your desired behavior ?Kicksorter
I want both items changed in half viewQuezada
D
1

In my opinion the best practice in this case is to bind the view[s] to a view group in the adapter. In your adapter you should create a linear layout and add as much children as you want

public Object instantiateItem(ViewGroup container, int position) { 
   LinearLayout ll = new LinearLayout(context);
   LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(0,MATCH_PART);
   param.weight = 1.0f;

   for (int i; i < getChildrenInPage() ; i++) {
      MyView myView = View.inflate(context, R.layout.my_layout, null)
      myView.bind(getDataForPosition(getChildrenInPage()*position + i))
      ll.add(myView, params));
   }
}
Dior answered 13/9, 2016 at 9:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.