1

I've got a card view having a maps fragment followed by a button inside a ScrollView. In portrait view, the fragment displays with proper height but doesn't scroll and so the button doesn't even appear. In landscape view, it does scroll but the fragment displays as a thin strip. Here is the code. I even tried to keep the fragment outside the card view, but even that didn't help, having the same results.

Images: http://postimg.org/gallery/w7chuz4u/

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<include
    android:id="@+id/app_bar"
    layout="@layout/app_bar" />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp"
            android:elevation="2dp"
            app:cardUseCompatPadding="true">

            <LinearLayout

                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:padding="8dp">
            ...
               <fragment
                  android:id="@+id/map"
                  android:name="com.google.android.gms.maps.SupportMapFragment"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginTop="5dp"
                  android:padding="5dp" />
            </LinearLayout>
        </android.support.v7.widget.CardView>


        <Button
            android:id="@+id/book"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:background="#ff0097a7"
            android:text="Book Appointment" />
    </LinearLayout>
</ScrollView>

app_bar.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#009688"
>
</android.support.v7.widget.Toolbar>
5
  • Do you need the app bar layout there? Commented Sep 27, 2015 at 10:17
  • yes. as I'm using a toolbar Commented Sep 27, 2015 at 13:32
  • provide your @layout/app_bar xml file Commented Sep 27, 2015 at 13:33
  • @YashTrivedi did you want to zoom in and zoom out the Map or you only want to see the map. Commented Sep 29, 2015 at 15:38
  • Zoom in zoom out too @Waleed Sarwar Commented Sep 30, 2015 at 16:27

1 Answer 1

1

Give Specific layout_height to your map fragment instead of wrap content like below.

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:layout_marginTop="5dp"
    android:padding="5dp" />

But it might not work in landscape view because you only put fragment and button inside scrollView .So in landscape view your list will take all the screen so and you will not be able to scroll because you didn't put list inside scrollview

Sign up to request clarification or add additional context in comments.

5 Comments

but why? shouldn't it work with wrap content. And in portrait layout if it is showing properly then why it is not scrolling?
As you said that in Landscape view it is scrolling but map is shown as thin strip.Because you did not give it some specific hieght
but what about portrait?
I don't know why in portrait layout you view showing properly because it should not show properly when i set fragment layout_height to wrap_content,It shows me like thin strip as it have show you in landscape,Please check below link dropbox.com/s/ffxp5k6hzha4upq/device-2015-09-27-185742.png?dl=0
when I keep height of the scrollview as wrap content or the height of linear layout as fill parent, the same thin strip appears. If I don't use a scrollview it views as expected, basically what is displayed currently

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.