如何创建一个水平滚动视图与ViewPager功能? [英] How do I create a Horizontal Scroll View with ViewPager functionality?
问题描述
我试图找出一种方法,通过使用viewpager来解决这个问题,但我已经无法这样做完全。
I've tried figuring out a way to solve this problem by using the viewpager but I've been unable to do so entirely.
下面是我已分配到解决任务:
Here is the tasks I have been assigned to solve:
- 创建一个视图,允许分页*(使用查看传呼机和两个片段之间的交换解决)
- 有两个视图共享相同背景的parallaxing效果(例如:pagin绿色视图时,下面的红色视图元素移动比背景稍微慢一点)
- 找到一种方法,这两种观点的共享的图形。我们的想法是对红色视图一个动画跨越到绿色视图。
有没有办法在Android平台上解决这个吗?有一个方法来简单地定义一个布局比所述电话尺寸大并以某种方式能够页面视图的可见部分和不可见部分之间?
Is there any way of solving this on the Android platform? Is there a way to simply define one layout that is larger than the phones dimension and somehow be able to page between the visible part of the view and the non-visible part?
推荐答案
您应该在onInterceptTouchEvent。当你点击horizontalScrollview你应该返回false在onInterceptTouchEvent否则返回true;
you should work on onInterceptTouchEvent. when you click on the horizontalScrollview you should return false in onInterceptTouchEvent else return true;
下面是,我该怎么做
1)使CustomViewpager延伸ViewPager 2)覆盖onInterceptTouchEvent像这样
1)make CustomViewpager extending ViewPager 2)override onInterceptTouchEvent like this
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (childId > 0) {
View scroll = findViewById(childId);
if (scroll != null) {
Rect rect = new Rect();
scroll.getHitRect(rect);
if (rect.contains((int) event.getX(), (int) event.getY())) {
return false;
}
}
}
return true;
}
private int childId;
public void setChildId(int id) {
this.childId = id;
}
3)在XML中这样使用,而不是viewpager customViewpager
3)use customViewpager instead of viewpager in xml like this
<com.packagename.CustomViewpager .....
4),并从这样的活动设置childId
4) and set childId from activity like this
CustomViewpager cv=(CustomViewpager)findViewById(R.id.id_of_customviewpager);
cv.setChildId(R.id.id_of_customviewpager);
5)完成
逻辑是其他明智给予的触摸到父
Logic is when you touch HorizontalScrollview give the touch to child other wise give touch to parent
这篇关于如何创建一个水平滚动视图与ViewPager功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!