[英]ViewPager.instantiateItem() position
I am trying to figure out a view´s absolute position, but so far it seems more like a relative position which gets passed, but then again, it also seems at times that it is based on pure randomness? 我正在尝试找出视图的绝对位置,但到目前为止,它似乎更像是通过了相对位置,但是再一次,有时似乎还基于纯随机性吗?
Look at this output I have from my ViewPager, switching between 5 views forth, back and forth again, I cannot find any pattern in it: 看一下我从ViewPager获得的输出,在5个视图之间来回切换,我在其中找不到任何模式:
size: 0, pos: 0 size: 1, pos: 1 size: 2, pos: 2 size: 2, pos: 3 size: 2, pos: 4 size: 2, pos: 2 size: 3, pos: 1 size: 3, pos: 0 size: 2, pos: 2 size: 2, pos: 3 size: 2, pos: 4
Basically what I am doing is trying to get the respective ListAdapter for each ListView in my ViewPagerAdapter, and then set them accordingly to their respective views (ListAdapter for the first list gets added to the first view eg.) this breaks however since the position given as argument in instantiateItem seems to not really follow any pattern. 基本上我正在做的是试图获取我的ViewPagerAdapter中每个ListView的相应ListAdapter,然后将它们相应地设置为其各自的视图(例如,第一个列表的ListAdapter被添加到了第一个视图中),但是由于指定的位置,这会中断因为InstantiateItem中的参数似乎并没有真正遵循任何模式。
So, is there any way to find out what the absolute position of a View in PagerView is? 那么,有什么方法可以找出View在PagerView中的绝对位置是什么?
Ok - I just fixed the problem myself, what I thought was the problem was actually not, I just think I kind of misunderstood how instantiateItem works. 好的-我自己解决了这个问题,我认为实际上不是问题,我只是误解了InstantimateItem的工作方式。 What I was trying to do was to get the current ListAdapter from my ViewPager, and I of course then thought I might as well retrive it from ViewPager.getChildAt(), but this of course is not the right procedure, because ViewPager only remembers the current View, and one View forth and back. 我试图做的是从ViewPager中获取当前的ListAdapter,然后我当然认为我也可以从ViewPager.getChildAt()中检索它,但这当然不是正确的过程,因为ViewPager只记得当前视图,以及一个前后视图。 The right way to do it, is to save the views in a ViewPagerAdapter, and then retrieve the Views from there when you need to reference them. 正确的方法是将视图保存在ViewPagerAdapter中,然后在需要引用它们时从那里检索视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.