在viewpager页面中mapview的手势问题

Dea*_*ely 21 android google-maps android-viewpager

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

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

有什么办法可以让这件事发生吗?
谢谢,加里

<?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>
Run Code Online (Sandbox Code Playgroud)

Jor*_*lar 47

当然有:

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

}
Run Code Online (Sandbox Code Playgroud)

这将使地图忽略地图内的所有幻灯片,只关心地图外的幻灯片/拖动.希望能帮助到你.(我现在正在使用水平滚动的webview)

编辑:忘记提及您需要在yout布局中使用CustomViewPager而不是ViewPager.

<com.yourpackage.CustomViewPager
            android:id="@+id/viewpager"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
        />
Run Code Online (Sandbox Code Playgroud)

  • 如何解决“ViewPager2”的问题? (2认同)

Vil*_*usK 11

如果使用Google Maps V2,请使用

.scrollingView.getClass()getPackage()的getName()startsWith( "映射").canScroll方法:

@Override
protected boolean canScroll(View scrollingView, boolean checkV, int dx, int x, int y) {
    if (scrollingView.getClass().getPackage().getName().startsWith("maps.")) {
        return true;
    }
    return super.canScroll(scrollingView, checkV, dx, x, y);
}
Run Code Online (Sandbox Code Playgroud)

becase的scrollingViewmaps.jb使用地图时V2.

同样在我的代码中,使用了以下类:

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
Run Code Online (Sandbox Code Playgroud)