android – 为每个视图充气新的布局xml – PagerAdapter中的instantiateItem

android – 为每个视图充气新的布局xml – PagerAdapter中的instantiateItem,第1张

概述所以基本上我想在ViewPager中填充页面,为每个视图位置使用单独的 XML布局.我现在正在这样做 @Override public Object instantiateItem(View container, int position) { LayoutInflater inflater = (LayoutInflater) mContext.getSystemSer 所以基本上我想在VIEwPager中填充页面,为每个视图位置使用单独的 XML布局.我现在正在这样做
@OverrIDe    public Object instantiateItem(VIEw container,int position) {        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE);        if(position == 0){        vIEw = inflater.inflate(R.layout.main,null);        ((VIEwPager) container).addVIEw(vIEw,0);        }        if(position == 1){            vIEw = inflater.inflate(R.layout.main_second,null);            ((VIEwPager) container).addVIEw(vIEw,0);        }        if(position == 2){            vIEw = inflater.inflate(R.layout.main_third,0);        }        return vIEw;}

首先正确显示视图,但是当我滑动VIEwPager时,将隐藏/销毁布局.为什么是这样?我这样做是错误的吗?请帮助并纠正我.

谢谢.
爱.韦斯利

解决方法 查看 this link以获得有关如何将它们放在一起的好教程.基本上这个想法是你必须将新增加的视图添加到VIEwPager集合:
VIEw vIEw = inflater.inflate(resID,null);((VIEwPager) collection).addVIEw(vIEw,0);
总结

以上是内存溢出为你收集整理的android – 为每个视图充气新的布局xml – PagerAdapter中的instantiateItem全部内容,希望文章能够帮你解决android – 为每个视图充气新的布局xml – PagerAdapter中的instantiateItem所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1136463.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存