禁用&安培;在Android中启用寻呼ViewPager [英] Disabling & Enabling Paging In ViewPager in Android
问题描述
我采用了android兼容包4版在我的应用程序中显示PDF页面。
我已经使用PagerAdapter&放大器; ViewPager显示PDF页面喜欢横向滚动视图。
I am using android compatibility package version 4 for displaying pdf pages in my app. I have used PagerAdapter & ViewPager for displaying pdf pages like horizontal scroll view.
现在的问题是分页相关stuff.I是能够通过根据此线程<一的viewpager内检测孩子的停止寻呼href=\"http://stackoverflow.com/questions/6920137/android-viewpager-and-horizontalscrollview\">android: ViewPager和HorizontalScrollVIew ,但如何才能够达到回来时,用户触摸视图外。我用下面的code为CustomViewPager。
Now the problem is in paging related stuff.I am able to stop paging by detecting childs inside the viewpager according to this thread android: ViewPager and HorizontalScrollVIew, but how can I can enable that back when user touches outside of that view. I have used following code for CustomViewPager.
public class CustomViewPager extends ViewPager {
private boolean enabled;
private int childId;
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
this.enabled = true;
}
public void setChildId(int childId) {
this.childId = childId;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
boolean result = false;
View scroll = getChildAt(childId);
if (scroll != null) {
Rect rect = new Rect();
CommonLogic.logMessage("PDF Page Rectangle ", TAG, Log.VERBOSE);
scroll.getHitRect(rect);
if (rect.contains((int) event.getX(), (int) event.getY())) {
setPagingEnabled(false);
result = true;
}
}
return result;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (this.enabled) {
return super.onTouchEvent(event);
}
return false;
}
public void setPagingEnabled(boolean enabled) {
this.enabled = enabled;
}
}
在尝试将PDF页面之外触摸然后也是如果(滚动!= NULL)
在这两个方向为真。
When try to touch outside the pdf page then also that if(scroll!=null)
becomes true in both orientation.
任何一个可以帮助我如何启用回去,这样分页将ViewPager继续。
Can any one help me out how to enable it back so that paging will continue in ViewPager.
推荐答案
我是有需要捏放大页面图像文件类似的问题。简单地说孤男寡女共处一的方式,当图像放大到禁用分页,使它显示在整个图像时。我解决了它这样的,并认为你可以做类似的事情。
首先扩展:类MyViewPager扩展ViewPager {...}
然后在这个类中重写以下两种方法
I was having a similar problem with paging image files that need pinch to zoom. Simply put Needing a way to disable paging when image is zoomed in and enable it when the whole image is shown. I solved it like this and think you could do a similar thing. First extend : class MyViewPager extends ViewPager {...} And then in that class override following two methods
@Override
public boolean onTouchEvent(MotionEvent event) {
if (YOUR_CRITERIA_TOENABLE_DISABLE) {
return true;
} else {
return super.onTouchEvent(event);
}
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return super.onInterceptTouchEvent(event);
}
请务必使用您的视图寻呼机在XML布局或code动态创建。
Be sure to use your view pager in xml layouts or dynamic creation from code.
这篇关于禁用&安培;在Android中启用寻呼ViewPager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!