gpt4 book ai didi

android - 动态更改 ViewPager 或 PagerAdapter 中 PagerIndicator 的计数

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:36:41 24 4
gpt4 key购买 nike

enter image description here

我想要的效果是:

  1. 当页面宽度为一半时,底圈指示器的数量必须为页面数的一半。

  2. 当页面宽度已满时,Bottom Circle indicator 的数量必须与页面数一样多。

还有一个要求:

  1. 当页面宽度为一半时,我可以一次滚动两个页面吗?
  2. 当页面宽度已满时,单次滚动只滚动一页?

页面宽度通过PagerAdapter#getPageWidth()获取

谁能给出完美的解决方案?没有制作两个布局文件或两个适配器?

这是我为实现这个基于 GIF 的 Activity 而开发的完整源代码。

问题改进将被接受。

https://github.com/raghavsatyadev/DemoPort

最佳答案

在我看来,这种情况下的最佳做法是将 View [s] 绑定(bind)到适配器中的 View 组。在您的适配器中,您应该创建一个线性布局并根据需要添加尽可能多的 child

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));
}
}

关于android - 动态更改 ViewPager 或 PagerAdapter 中 PagerIndicator 的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39266534/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com