Reputation: 33
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>
Upvotes: 1
Views: 4207
Reputation: 2374
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
Upvotes: 1