viewpager 页面中 mapview 的手势问题 [英] gesture issue with mapview in viewpager page

查看:13
本文介绍了viewpager 页面中 mapview 的手势问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的主界面是一个viewpager,用户只需水平滑动页面即可到达各个页面.其中一页有一个谷歌地图视图(粘贴在下面).我的问题是,如果用户在地图页面上并使用水平滑动手势,页面会滑动到下一页而不是地图横向移动.就好像 viewpager 在地图之前获取手势一样.

My app's main interface is a viewpager where the user just slides the pages horizontally to get to the various pages. One of the pages has a google mapview (pasted below). My problem is that if the user is on the map page and uses a horizontal slide gesture, the page slides to the next page instead of the map moving sideways. It's as if the viewpager is getting the gesture before the map.

如果用户很聪明并开始沿对角线或垂直方向滑动地图,则地图开始移动,然后手势可以水平继续.但我更喜欢地图移动而不是简单的水平滑动手势上的页面.页面始终可以使用 textview 滑动.

If the user is clever and begins sliding the map in a diagonal or vertical direction the map begins moving and then the gesture can continue horizontally. But I would prefer the map move instead of the page on a simple horizontal slide gesture. The page can always be slid using the textview.

有什么办法可以做到这一点?
谢谢,加里

Is there any way I can make this happen?
thanks, Gary

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ContentPanel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

 <TextView
    android:id="@+id/tvMAP"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Map"
    style="@style/bigtype" />


<com.google.android.maps.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:apiKey="mykeygoeshere"
    android:clickable="true" />

</LinearLayout>

推荐答案

当然有:

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);
    }

}

这将使地图忽略地图内的所有幻灯片,而只关心地图外的幻灯片/拖动.希望能帮助到你.(我现在为带有水平滚动的 webview 执行此操作)

This will make the map ignore all the slides inside the map and just care about the slides/draggs outside the map. Hope it helps. (I do this right now for a webview with horizontal scroll)

忘了提到你需要在布局中使用 CustomViewPager 而不是 ViewPager.

Forgot to mention that instead of the ViewPager you need to use the CustomViewPager in yout layout.

<com.yourpackage.CustomViewPager
            android:id="@+id/viewpager"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
        />

这篇关于viewpager 页面中 mapview 的手势问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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