【问题标题】:PagerAdapter returns wrong position for Multi View PagerPagerAdapter 为多视图寻呼机返回错误的位置
【发布时间】:2016-08-24 06:07:36
【问题描述】:

我正在通过调整页边距来实现类似视图寻呼机的 caurosel。我可以像下面这样实现

但我遇到了 PagerAdapter 的问题

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View view= inflater.inflate(R.layout.mylayout, null);

    // 
    Button btn=(Button)view.findViewById(R.id.button1);
    btn.setTag(position);
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          Log.e("position",v.getTag()+"");
       }
   }
    return imgView;
}

虽然我正在设置标签,但我只能为中心页面(所选项目)获得正确的位置,但是当我单击左侧页面的按钮时,它会返回错误的值。

我已经搜索了很多关于这个问题的方法,到目前为止我找不到解决方案。

寻求您的帮助。

谢谢

【问题讨论】:

    标签: android android-viewpager android-pageradapter


    【解决方案1】:

    你可以使用 RecyclerView

    LinearLayoutManager layoutManager = ...
    recyclerView.setLayoutManager(layoutManager);
    
    //when you want horizontal
    layoutManager.setOrientation(context,LinearLayoutManager.HORIZONTAL,false);
    
    //when you want vertical
    layoutManager.setOrientation(context,LinearLayoutManager.VERTICAL,false);
    

    【讨论】:

    • 感谢您的快速回复。我正在处理非常旧的代码库。pagerAdapter 是否有任何调整以快速修复
    【解决方案2】:

    PagerAdapter 没有问题。实际问题是由于我用作包装动画视图的第三方库。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-17
      • 1970-01-01
      • 2014-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-05
      相关资源
      最近更新 更多