gpt4 book ai didi

android - 谷歌地图 fragment 在 N​​estedScrollView 内滚动

转载 作者:太空宇宙 更新时间:2023-11-03 11:27:54 25 4
gpt4 key购买 nike

我有一个 NestedScrollView 作为父级,Fragment 包含 googleMap 作为它的子级。当我在 map 中向下或向上滚动时,NesetdScrollView 是滚动的,我无法在 map 内滚动。到目前为止,我已经尝试通过创建透明图像来解决堆栈溢出问题,但它对我不起作用。

XML:

  <android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/car_progress"
android:id="@+id/nested_scroll"
android:visibility="gone"

>
............
............
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/first_section"
android:visibility="gone"
android:id="@+id/map_wrapper"
android:orientation="vertical"
android:layout_marginTop="10dp"
>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/dealer_location"
android:textAllCaps="true"
android:textColor="@color/colorPrimary"
style="@style/BoldStyle"
android:layout_marginLeft="@dimen/single_title_dimen"
android:layout_marginRight="@dimen/single_title_dimen"
android:id="@+id/dealer_head"

/>

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_below="@+id/dealer_head"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imagetrans"
android:layout_alignTop="@+id/map"
android:layout_alignBottom="@+id/map"
android:layout_alignEnd="@+id/map"
android:layout_alignRight="@+id/map"
android:layout_alignLeft="@+id/map"
android:layout_alignStart="@+id/map"
android:src="@android:color/transparent"/>

</RelativeLayout>
.....
.....
</android.support.v4.widget.NestedScrollView>

代码:

transImg.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
nv.requestDisallowInterceptTouchEvent(true);
// Disable touch on transparent view
return false;

case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
nv.requestDisallowInterceptTouchEvent(false);
return true;

case MotionEvent.ACTION_MOVE:
nv.requestDisallowInterceptTouchEvent(true);
return false;

default:
return true;
}
}
});

最佳答案

试试这个...使用这个带有可触摸包装器的自定义 map fragment 。

MySupportMapFragment mSupportMapFragment;
mSupportMapFragment = (MySupportMapFragment) getChildFragmentManager().findFragmentById(R.id.googleMap);
if(mSupportMapFragment != null)
mSupportMapFragment.setListener(new MySupportMapFragment.OnTouchListener() {
@Override
public void onTouch() {
scrollView.requestDisallowInterceptTouchEvent(true);
}
});

MySupportMapFragment

public class MySupportMapFragment extends SupportMapFragment {

private OnTouchListener mListener;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {

View layout = super.onCreateView(inflater, parent, savedInstanceState);

TouchableWrapper frameLayout = new TouchableWrapper(getActivity());
frameLayout.setBackgroundColor(getResources().getColor(android.R.color.transparent));
((ViewGroup) layout).addView(frameLayout,
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

return layout;
}

public void setListener(OnTouchListener listener) {
mListener = listener;
}

public interface OnTouchListener {
public abstract void onTouch();
}

public class TouchableWrapper extends FrameLayout {

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

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mListener.onTouch();
break;
case MotionEvent.ACTION_UP:
mListener.onTouch();
break;
}
return super.dispatchTouchEvent(event);
}
}
}

关于android - 谷歌地图 fragment 在 N​​estedScrollView 内滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41689968/

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