DoubleVoid DoubleVoid - 1 month ago 9
Android Question

Vertical LinearLayout, making the map shrink the more controls are added

I want to display a Google map and 2 controls below it.
How do I achieve this?! I tried it this way:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/map"
tools:layout="@android:layout/browser_link_context_header" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/edOrderLocation"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<Spinner
android:id="@+id/spinJobType"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
</LinearLayout>
</LinearLayout>


The controls are not visible, the whole screen takes up the map.
I want the controls to be visible at the bottom of the screen and thus reduzing the size of the fragment accordingly

Answer

Try this -

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<fragment
    android:layout_alignParentTop="true"
    android:layout_above="@+id/controls_container"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/map"
    tools:layout="@android:layout/browser_link_context_header" />

<LinearLayout
    android:id="@id/controls_container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_alignParentBottom="true">
    <EditText
        android:id="@+id/edOrderLocation"
        android:layout_height="wrap_content"
        android:layout_width="match_parent" />
    <Spinner
        android:id="@+id/spinJobType"
        android:layout_height="wrap_content"
        android:layout_width="match_parent" />
</LinearLayout>
</RelativeLayout>
Comments