Open fuchaosz opened 8 years ago
What specific problem are you experiencing with a ViewPager? I have a ViewPager inside a RelativeLayout and have not had any problems with setOnPagerChangeListener()
.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="48dip"
android:background="@drawable/background_tabs" />
<android.support.v4.view.ViewPager
android:id="@+id/quicknav_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tabs" />
</RelativeLayout>
@theBlbDan I'm not mean setOnPagerChangeListener()
, I mean 'addIgnoreView()' is useless in somehow, for more detail, please see my csdn bolg here:
http://blog.csdn.net/fuchaosz/article/details/51513288
In English: I found the method "addIgnoredView()" is useless, when a view in ViewGroup. for example:
slidingMenu.addIgnoredView(viewpager);
now it's useless and the viewpager can neither get the ACTION_DOWN,ACTION_MOVE,ACTION_UP nor "setOnPagerChangeListener()" , because of this(in CustomViewAbove.java):v.getHitRect(rect). this method only get the location of v releated to it's parent, but the MotionEvent who's location is the whole screen,so
rect.contains((int)ev.getX(), (int)ev.getY())
always return false, even if your touch point is in the ignored view. How to fix it? look at this:use
v.getGlobalVisibleRect(rect);
inplace of `v.getHitRect(rect);for more detail,please see my csdn blog: http://blog.csdn.net/fuchaosz/article/details/51513288
中文: 当一个子view嵌套在ViewGroup中,将这个子View加入SlidingMenu的ignoredViews中,即:slidingMenu.addIgnoredView(v),是不起作用的,例如:一个LinearLayout中包含一个ViewerPager,此时ViewPager的滑动事件会和SlidingMenu冲突,这时ViewPager将不能滑动,怎么办呢?可以调用slidingMenu.addIgnoredView(viewPager),然而这是无效的,原因在这里(在CustomViewAbove.java):
v.getHitRect(rect)
取的的坐标是相对于父view的,但是MotionEvent的坐标是整个屏幕的,所以会导致rect.contains((int)ev.getX(), (int)ev.getY())
始终返回false,即使你点击的区域是viewPager的区域 怎么修复?看下面的方法:用
v.getGlobalVisibleRect(rect);
代替v.getHitRect(rect);
更多详细信息,请看我的csdn博客:http://blog.csdn.net/fuchaosz/article/details/51513288