What effect I want to have is :
number of Bottom Circle indicator must be half of page count when page width is half.
number of Bottom Circle indicator must be as much as page count when page width is full.
also, there is an another request:
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
ViewPager2 is an improved version of the ViewPager library that offers enhanced functionality and addresses common difficulties with using ViewPager . If your app already uses ViewPager , read this page to learn more about migrating to ViewPager2 .
ViewPager in Android is a class that allows the user to flip left and right through pages of data. This class provides the functionality to flip pages in app. It is a widget found in the support library. To use it you'll have to put the element inside your XML layout file that'll contain multiple child views.
You can't use ViewPager to swipe between Activities . You need to convert each of you five Activities into Fragments , then combine everything in one FragmentActivity with the Adapter you use with ViewPager .
PagerAdapter supports data set changes. Data set changes must occur on the main thread and must end with a call to notifyDataSetChanged similar to AdapterView adapters derived from android. widget. BaseAdapter . A data set change may involve pages being added, removed, or changing position.
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));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With