编辑:看到了自己的答案简单的解决方案
See my own answer for easy solution
重要:赏金供清晰的方式来修改ViewPager满足下面列出的场景。请不要提供HorizontalScrollView - 我需要全生命周期的片段场景覆盖的
我需要实施片段
为基础的观点,其中一个项目是在中心和项目水平滚动的左/右部分或完全可见。 ViewPager
病适合的任务,因为它专注于显示一个项目在每个时间。
I need to implement horizontal scrolling of Fragments
-based views in which one item is in the center and items to the right/left are partially or fully visible. ViewPager
is ill suitable for the task since it's focused on displaying one item at each time.
要更容易地理解下面是一个快速草图,其中1,5和6项是可视区域之外。而且,想使这个可视数字配置的,因此例如在纵向视图我将只显示2(或可能只有一个)项目。
To make it easier to understand below is a quick sketch in which items 1, 5 and 6 are outside of viewable area. And and want to make this viewable number configurable so for example in portrait view I will only show 2 (or possibly just one) items.
我不是适合说3个项目在屏幕上,只要中央项目显示为其他人可以进行裁剪。在小屏幕即可有1个中心项目,并在尺寸多为画面的增长(裁剪即可)项应显示
I'm not trying to fit say 3 items on the screen, as long as central item is shown others can be cropped. On the small screen is OK to have 1 central item and as screen grows in size multiple (cropped is OK) items should be shown
据我所知,这看起来像一个画廊但同样的项目不是简单的图像,但片段
与垂直滚动列表中的每个片段
I understand that this looks like a gallery but again the items are not simple images but Fragments
with a vertically scrollable list in each fragment
P.S。发现这个博文由@Commonsware的列表3种不同的方法的。对于我的需要,我喜欢#3
P.S. Found this blogpost by @Commonsware that list 3 different approaches. For my need I like #3
推荐答案
这其中有令人惊讶的简单的答案,我甚至不知道为什么它没有公布的时候了。所有这一切,我需要做的就是确切的作用是覆盖 PagerAdapter#getPageWidth
方法。默认情况下它返回1,但如果你将其设置为0.5,你会得到2页,0.33会给你3等。根据宽度寻呼机项之间的分隔符,你可能要稍微降低的价值。
This one has surprisingly easy answer, I'm not even sure why it wasn't posted right away. All that I needed to do to get the exact effect was to override PagerAdapter#getPageWidth
method. By default it returns 1 but if you set it to 0.5 you will get 2 pages, 0.33 will give you 3, etc. Depending on width of the separator between pager items you may have to slightly decrease the value.
请参阅下面的代码片断:
See the following snippet:
@Override
public float getPageWidth(final int position) {
// this will have 3 pages in a single view
return 0.32f;
}
相关推荐
最新文章