动态更改 ViewPager 或 PagerAdapter 中 PagerIndicator 的计数
Dynamically change count of PagerIndicator in ViewPager or PagerAdapter
我想要的效果是:
当页面宽度为一半时,底部圆圈指示符的数量必须为页面数的一半。
当页面宽度已满时,底部圆圈指示符的数量必须与页数一样多。
另外,还有一个要求:
- 当页面宽度为一半时,我可以一次滚动两个页面吗?
- 当页面宽度已满时,单次滚动只滚动一页?
页面宽度由PagerAdapter获取#getPageWidth()
谁能给出完美的解决方案?没有制作两个布局文件或两个适配器?
这是我为实现这个基于 activity 的 GIF 而开发的全部源代码。
问题改进将被接受。
在我看来,这种情况下的最佳做法是将视图 [s] 绑定到适配器中的视图组。在您的适配器中,您应该创建一个线性布局并根据需要添加尽可能多的 children
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));
}
}
我想要的效果是:
当页面宽度为一半时,底部圆圈指示符的数量必须为页面数的一半。
当页面宽度已满时,底部圆圈指示符的数量必须与页数一样多。
另外,还有一个要求:
- 当页面宽度为一半时,我可以一次滚动两个页面吗?
- 当页面宽度已满时,单次滚动只滚动一页?
页面宽度由PagerAdapter获取#getPageWidth()
谁能给出完美的解决方案?没有制作两个布局文件或两个适配器?
这是我为实现这个基于 activity 的 GIF 而开发的全部源代码。
问题改进将被接受。
在我看来,这种情况下的最佳做法是将视图 [s] 绑定到适配器中的视图组。在您的适配器中,您应该创建一个线性布局并根据需要添加尽可能多的 children
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));
}
}