必需的android.gms.maps.GoogleMap找到com.examle.myprojec.WorkAroundFragment
首先,我知道getMap()方法已被弃用,但为了避免在map中使用scrollview,我使用了以下方法: 创建自定义片段。但是,在getMap()点上,我不知道该怎么办 这是我的自定义片段:必需的android.gms.maps.GoogleMap找到com.examle.myprojec.WorkAroundFragment,android,google-maps,android-fragments,android-scrollview,Android,Google Maps,Android Fragments,Android Scrollview,首先,我知道getMap()方法已被弃用,但为了避免在map中使用scrollview,我使用了以下方法: 创建自定义片段。但是,在getMap()点上,我不知道该怎么办 这是我的自定义片段: public class WorkaroundMapFragment extends SupportMapFragment { private OnTouchListener mListener; @Override public View onCreateView(Layout
public class WorkaroundMapFragment extends SupportMapFragment {
private OnTouchListener mListener;
@Override
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle savedInstance) {
View layout = super.onCreateView(layoutInflater, viewGroup, savedInstance);
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);
}
}
}
以下是mapfragment的xml代码:
<fragment xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/guideline3"
tools:context="com.example.mapwithmarker.MapsMarkerActivity"
class="com.example.jonida.restsapp.customFragment.WorkaroundMapFragment"/>
如果您有任何建议,我将不胜感激,谢谢
必需的android.gms.maps.GoogleMap找到com.examle.myprojec.WorkAroundFragment
根据您的错误,您需要将您的
声明为解决方案映射片段
而不是谷歌地图
用这个
private WorkaroundMapFragment googleMap = (WorkaroundMapFragment) getChildFragmentManager()
.findFragmentById(R.id.map);
googleMap.getMapAsync(this);
((WorkaroundMapFragment) getChildFragmentManager().findFragmentById(R.id.flysl_map))
.setListener(new WorkaroundMapFragment.OnTouchListener() {
@Override
public void onTouch() {
mScrollView.requestDisallowInterceptTouchEvent(true);
}
});
而不是这个
googleMap=((WorkaroundMapFragment)getChildFragmentManager().findFragmentById(R.id.map)).getMap //Here is my problem :/ ;
((WorkaroundMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).setListener(new WorkaroundMapFragment.OnTouchListener() {
@Override
public void onTouch() {
mScrollView.requestDisallowInterceptTouchEvent(true);}});
编辑
<fragment xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/guideline3"
tools:context="com.example.mapwithmarker.MapsMarkerActivity"
class="com.example.jonida.restsapp.customFragment.WorkaroundMapFragment"/>
查看片段中的class=“com.example.jonida.restsapp.customFragment.WorkaroundMapFragment。嗯,您认为有问题吗?谢谢谢谢YOUUU@FatjonRrapaj很高兴能帮助你我刚刚做了:D:)
<fragment xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/guideline3"
tools:context="com.example.mapwithmarker.MapsMarkerActivity"
class="com.example.jonida.restsapp.customFragment.WorkaroundMapFragment"/>