禁用刷卡的ViewPager的选项卡之一的 [英] Disable the swipe in one of ViewPager's tabs

查看:126
本文介绍了禁用刷卡的ViewPager的选项卡之一的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/12117791/gesture-issue-with-mapview-in-viewpager-page">gesture问题图形页面中viewpager页面

我使用的模板,使我们在标签之间横向轻扫

I use the template that allow us to swipe horizontally between tabs

但我的标签之一是图形页面,所以当我刷卡左/右在图形页面,就会切换移动地图上的标签来代替。

But one of my tab is MapView, so when I swipe left/right in that MapView, it will switch tab instead of moving the map.

有没有什么办法来禁用手势仅在该图形页面标签?

Is there any way to disable the gesture only in that MapView tab?

感谢

推荐答案

我发现从的这个问题

在情况下,链接是死的,我在这里复制了code:

In case the link is dead, I copied the code here:

请一个新的类与此完全相同的code,它将prevent图形页面,以留出地图相关的姿态接受任何其他的手势。不要忘记添加你的进口(CTRL + SHIFT + O)上述这些code

Make a new class with this exact code, it will prevent MapView to receive any other gesture aside of map-related gesture. Don't forget to add your package and import (CTRL+SHIFT+O) above these code

public class CustomViewPager extends ViewPager {

    public CustomViewPager(Context context) {
        super(context);
    }

    public CustomViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
        if (v instanceof MapView) {
            return true;
        }
        return super.canScroll(v, checkV, dx, x, y);
    }
}

然后在的main.xml 修改&LT; android.support.v4.view.ViewPager ... /&GT; 到这一点:

<com.yourPackage.CustomViewPager
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Main" />

由于豪尔赫·阿吉拉尔在这个问题的答案!

Thanks to Jorge Aguilar for the answer in that question!

这篇关于禁用刷卡的ViewPager的选项卡之一的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆