gpt4 book ai didi

android - viewpager 页面中 mapview 的手势问题

转载 作者:IT老高 更新时间:2023-10-28 23:02:38 25 4
gpt4 key购买 nike

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

如果用户很聪明并开始沿对角线或垂直方向滑动 map ,则 map 开始移动,然后手势可以水平继续。但我更喜欢 map 移动而不是简单的水平滑动手势上的页面。页面始终可以使用 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>

最佳答案

当然有:

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

}

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

编辑:忘了提到你需要在布局中使用 CustomViewPager 而不是 ViewPager。

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

关于android - viewpager 页面中 mapview 的手势问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12117791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com