Вертикальное линейное отображение, уменьшающее карту по мере добавления большего количества элементов управления

#android #android-studio #android-linearlayout

#Android #android-studio #android-linearlayout

Вопрос:

Я хочу отобразить карту Google и 2 элемента управления под ней. Как мне этого добиться ?! Я попробовал это так:

 <?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>
 

Элементы управления не видны, карта занимает весь экран.
Я хочу, чтобы элементы управления были видны в нижней части экрана и, таким образом, соответствующим образом изменяли размер фрагмента

Комментарии:

1. Вы пытаетесь получить результат, подобный Google Map или что-то в этом роде? В этом случае вы можете использовать CollapsingToolbarLayout для этого. Можете ли вы показать, какой макет вы пытаетесь создать?

Ответ №1:

Попробуйте это —

 <?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>
 

Комментарии:

1. Вау, спасибо, работает как шарм! 🙂 android: layout_above, я думаю, здесь творит волшебство. Приятно!

2. Я хотел бы добавить еще одну вещь: не используйте пространство имен Android повторно.

3. Что именно вы имеете в виду?

4. удалить xmlns: android=» schemas.android.com/apk/res/android » из <фрагмента>