0

I have a scrollview that contains a section for an address, some buttons, and a map that I want to be displayed in the following format:

Template

Here is the result I get instead:

enter image description here

For some strange reason I can't force the MapFragment to respect the matchparent attribute and it always turns out to be a specific default height. Here's the basic XML:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/tile_view"
        android:orientation="vertical"
        android:padding="10dp">

        <!-- Address -->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="@style/agencyAddress"/>

        <!-- Map and Buttons -->
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:baselineAligned="false"
            android:paddingTop="5dp">

            <!-- Map -->
            <fragment
                android:id="@+id/agency_map"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_toRightOf="@+id/buttons"
                android:layout_toEndOf="@+id/buttons"
                class="com.google.android.gms.maps.MapFragment" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/buttons"
                android:orientation="vertical">

                <ImageButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/random_image"
                    android:src="@drawable/random_image"/>

                <ImageButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/random_image2"
                    android:src="@drawable/random_image"/>

            </LinearLayout>

        </RelativeLayout>

    </LinearLayout>
Eddie K
  • 503
  • 4
  • 18
  • Try wrapping the fragment in another layout, like LinearLayout and then match that with your RelativeLayout? – nem035 Sep 19 '14 at 20:10
  • Unfortunately that doesn't work either, neither with RelativeLayout nor LinearLayout. – Eddie K Sep 19 '14 at 20:16

2 Answers2

0

Add these two attributes to your nap fragment in the layout.

android:layout_alignTop="@+id/buttons" android:layout_alignBottom="@+id/buttons"

Simon
  • 10,932
  • 50
  • 49
0

Your code seems to be a little off. It's harder to capture what you're trying to do in a linear layout. The ImageView would be your fragment.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity$PlaceholderFragment">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/ic_launcher"
    android:orientation="vertical">

    <!-- Address -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Some Text"
        android:gravity="center"
        android:textSize="20dp"/>

    <!-- Map and Buttons -->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:baselineAligned="false"
        android:layout_gravity="center"
        android:padding="5dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/buttons"
            android:orientation="vertical">


            <ImageButton
                android:layout_width="75dp"
                android:layout_height="75dp"
                android:id="@+id/random_image"
                android:src="@drawable/ic_launcher"
                />

            <ImageButton
                android:layout_width="75dp"
                android:layout_height="75dp"
                android:id="@+id/random_image2"
                android:layout_below="@id/random_image"
                android:src="@drawable/ic_launcher"/>

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_toRightOf="@id/random_image"
                android:layout_alignBottom="@id/random_image2"
                android:layout_marginBottom="5dp"
                android:layout_marginTop="5dp"
                android:background="#000000"/>


        </RelativeLayout>

    </RelativeLayout>

</LinearLayout>

chr1st3nd0
  • 44
  • 3