1

I am trying to use a MapActivity inside a ScrollView page. When I run the app to test it, the map cant be clicked correctly because as the user tries to swipe on the map the scrollview takes over and kinda makes it hard to swipe on it.

Here is how it looks(Map included at the very bottom):

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".CreateAds.FurnitureAd.CreateFunP1Fragment">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/lll"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <EditText
                android:id="@+id/editText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="10"
                android:hint="@string/ad_title"
                android:inputType="textPersonName"
                android:textColor="@color/colorPrimary"
                tools:layout_editor_absoluteX="182dp"
                tools:layout_editor_absoluteY="16dp"
                android:importantForAutofill="no" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/rrr"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="@+id/lll"
            app:layout_constraintStart_toStartOf="@+id/lll"
            app:layout_constraintTop_toBottomOf="@+id/lll">

            <EditText
                android:id="@+id/editText2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:ems="10"
                android:hint="@string/offer_price"
                android:inputType="number"
                android:textColor="@color/colorPrimary"
                android:importantForAutofill="no" />
        </com.google.android.material.textfield.TextInputLayout>

        <TextView
            android:id="@+id/textView16"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="@string/currency"
            android:textColor="@color/colorPrimary"
            app:layout_constraintStart_toStartOf="@+id/spinner2"
            app:layout_constraintTop_toBottomOf="@+id/rrr" />

        <Spinner
            android:id="@+id/spinner2"
            style="@style/Widget.AppCompat.Spinner.Underlined"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="@+id/rrr"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="@+id/rrr"
            app:layout_constraintTop_toBottomOf="@+id/textView16" />

        <TextView
            android:id="@+id/textView18"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="@string/state"
            android:textColor="@color/colorPrimary"
            app:layout_constraintStart_toStartOf="@+id/spinner2"
            app:layout_constraintTop_toBottomOf="@+id/spinner2" />

        <Spinner
            android:id="@+id/spinner3"
            style="@style/Widget.AppCompat.Spinner.Underlined"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="@+id/spinner2"
            app:layout_constraintStart_toStartOf="@+id/spinner2"
            app:layout_constraintTop_toBottomOf="@+id/textView18" />

        <TextView
            android:id="@+id/textView20"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="@string/city"
            android:textColor="@color/colorPrimary"
            app:layout_constraintStart_toStartOf="@+id/spinner3"
            app:layout_constraintTop_toBottomOf="@+id/spinner3" />

        <Spinner
            android:id="@+id/spinner4"
            style="@style/Widget.AppCompat.Spinner.Underlined"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="@+id/spinner3"
            app:layout_constraintStart_toStartOf="@+id/spinner3"
            app:layout_constraintTop_toBottomOf="@+id/textView20" />

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/textInputLayout"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="@+id/spinner4"
            app:layout_constraintStart_toStartOf="@+id/spinner4"
            app:layout_constraintTop_toBottomOf="@+id/spinner4">

            <EditText
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:hint="@string/location"
                android:inputType="text"
                android:importantForAutofill="no" />

        </com.google.android.material.textfield.TextInputLayout>

        <TextView
            android:id="@+id/textView24"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="@string/map"
            android:textColor="@color/colorPrimary"
            app:layout_constraintStart_toStartOf="@+id/textInputLayout"
            app:layout_constraintTop_toBottomOf="@+id/textInputLayout" />

        <include
            layout="@layout/activity_maps"
            android:layout_width="0dp"
            android:layout_height="450dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView24" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

Is implementing it like this wrong?

RandomCoder
  • 395
  • 2
  • 10
  • Anything on a scrollable view might lose input as the scroll consumes the touch input. Put things with opposite direction inputs (e.g. horizontal lists) or otherwise limit it to clicking events that expands the map into its own fragment. – P Fuster Feb 26 '20 at 11:54

2 Answers2

2

Map activities are to be used when you want the map to be the main and pretty much the only thing on your activity. Use a MapFragment instead. Example:

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:name="com.google.android.gms.maps.SupportMapFragment"/>
92AlanC
  • 1,327
  • 2
  • 14
  • 33
  • If your fragment fills your entire activity then my advice is move the `ScrollView` to the activity and use the `MapFragment` as a separate fragment, or if you still want to keep the `MapFragment` inside your `CreateFunP1Fragment` then have a look at this question: https://stackoverflow.com/questions/6672066/fragment-inside-fragment – 92AlanC Feb 26 '20 at 12:02
  • Still got the same issue, I cant access it the scrollview takes over the touch – RandomCoder Feb 26 '20 at 12:02
  • How on earth could you have tried it in less than a minute? Give it a go and also try applying what @P Fuster mentioned in his comment – 92AlanC Feb 26 '20 at 12:09
  • 1
    Calm down :) I didnt mean the comment you left... I meant the fragment solution you gave as I tried diffee=rent things it started working the same way as the include worked thats why I deleted my 2 other comments – RandomCoder Feb 26 '20 at 12:12
2

What we did on this scenario was first to add some margin/padding to the map so that the user could scroll on its side.

But then we decided it was better to set that map in the ScrollView not interactive and set an invisible button on the top of it and when the user taps on the button a new activity opened with the map maximised. And there is no scroll in that new activity, the user can only interact with the map or go back.

The fragment which loaded the map was the same, so the code for the map was shared, it's just placed in two different layouts (inside the scrollview without interaction enabled and in the new activity).

jeprubio
  • 17,312
  • 5
  • 45
  • 56
  • 1
    Yeah I just figured it would be best to place a button on top of the map and on tap it takes him to the map activity, thanks for the suggestion! – RandomCoder Feb 27 '20 at 07:09