Wenn ich versuche, die Google Map zu schwenken, scrollt CoordinatorLayout nach unten, und natürlich möchte ich stattdessen die Karte schwenken. Wenn ich außerhalb der Karte halte und dann versuche zu schwenken, dann funktioniert es perfekt, aber das wäre keine sehr gute Endbenutzererfahrung.Scrollen beim Skalieren mit Google Maps API deaktivieren
Der OnTouchListener behebt einen Teil des Problems ... aber nur wenn ich horizontal schwenken. In dem Moment, in dem mein Finger nach oben oder unten geht, hört er auf, die Karte zu verschieben. Wie kann ich das beheben?
public class HomeFragment extends Fragment {
private TextView aboutTxt;
private SupportMapFragment mSupportMapFragment;
private GoogleMap mMap;
public HomeFragment() {
// Required empty public constructor
}
// TODO: Rename and change types and number of parameters
public static HomeFragment newInstance() {
HomeFragment fragment = new HomeFragment();
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home, container, false);
view.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction()==MotionEvent.ACTION_DOWN) {
Log.e(TAG,"Down");
return true;
}
if (event.getAction()==MotionEvent.ACTION_MOVE){
Log.e(TAG,"Move");
return true;
}
if (event.getAction()==MotionEvent.ACTION_UP){
Log.e(TAG,"Up");
return true;
}
return false;
}
});
mSupportMapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
if (mSupportMapFragment == null) {
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
mSupportMapFragment = SupportMapFragment.newInstance();
fragmentTransaction.replace(R.id.map, mSupportMapFragment).commit();
}
if (mSupportMapFragment != null) {
mSupportMapFragment.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
if (googleMap != null) {
mMap = googleMap;
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
// Add a marker in Sydney and move the camera
LatLng myMap = new LatLng(xx.xxxx, xx.xxxx);
mMap.addMarker(new MarkerOptions().position(gradiMap).title("My marker));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(myMap, 17));
}
}
});
}
XML
<android.support.design.widget.AppBarLayout
android:id="@+id/main.appbar"
android:layout_width="match_parent"
android:layout_height="300dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<FrameLayout
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/main.toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:id="@+id/aboutTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="8dp"
android:padding="@dimen/activity_horizontal_margin"
android:textColor="@color/colorBlack"
android:textSize="17sp" />
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/activity_horizontal_margin"
android:src="@drawable/whitestar"
app:layout_anchor="@id/main.appbar"
app:layout_anchorGravity="bottom|right|end" />
können Sie ein wenig mehr erklären bitte? Ich kann es immer noch nicht zur Arbeit bringen – r3dm4n
In Fällen wie diesem ist das erste, was ich tue, zu sehen, ob mein Abfangen irgendetwas überhaupt macht. Ändern Sie Ihre Methode "onInterceptTouchEvent", um jedes Mal den Wert "true" zurückzugeben und festzustellen, ob Berührungen in die Karte gelangen. Oder Sie könnten einen Breakpoint auf der 'switch'-Linie sehen und sehen, ob er jemals getroffen wird. – LukeWaggoner
Danke, dass Sie mich in die richtige Richtung weisen. Problem gelöst. – r3dm4n