0

Нужно разместить LinearLayout ниже ListView(типа список, а внизу кнопки). Но если явно не указывать высоту списка он занимает вниз все пространство. Делаю так.

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="#FFFFFF"
    android:id="@+id/marina"
    android:padding="10dp">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="#FF756C"
        android:id="@+id/marina"
        android:gravity="center">

        <Button
            android:layout_height="wrap_content"
            android:text="РЕКОМЕНДАЦИИ"
            android:layout_width="200dp"
            android:id="@+id/marinaButton1"
            android:background="#FF756C"
            android:fontFamily="sans-serif-thin"
            android:textColor="#FCFCFC"/>

        <Button
            android:layout_height="30dp"
            android:layout_width="30dp"
            android:id="@+id/marinaButton1"
            android:fontFamily="sans-serif-thin"
            android:textColor="#FCFCFC"
            android:background="@drawable/settings49"
            android:layout_marginRight="10dp"/>

    </LinearLayout>

    <Button
        android:layout_height="40dp"
        android:layout_width="40dp"
        android:id="@+id/marinaButton1"
        android:fontFamily="sans-serif-thin"
        android:textColor="#FCFCFC"
        android:background="@drawable/search100"
        android:layout_marginLeft="30dp"
        android:gravity="right"/>

</LinearLayout>

<ListView
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:id="@+id/marinaListView1"
    android:layout_below="@id/marina">

</ListView>

<LinearLayout
    android:layout_width="match_parent"
    android:orientation="horizontal"
    android:background="#FF5959"
    android:layout_height="wrap_content"
    android:gravity="left|center"
    android:id="@+id/marinaLinearPlay"
    android:layout_below="@id/marinaListView1">

    <Button
        android:layout_height="40dp"
        android:layout_width="40dp"
        android:background="@drawable/play105"/>

    <TextView
        android:layout_height="wrap_content"
        android:text="Винтаж  -  АМСТЕРДАМ"
        android:layout_width="wrap_content"
        android:layout_marginLeft="15dp"
        android:fontFamily="sans-serif-thin"/>

    <Button
        android:layout_height="30dp"
        android:layout_width="33dp"
        android:layout_marginLeft="100dp"
        android:background="@drawable/microsoft8"/>

</LinearLayout>

Нижний LinearLayout не видно.

0

1 ответ 1

0

Попробуйте так:

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

    <LinearLayout
        android:id="@+id/buttonsLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" >

        Ваши кнопки

    </LinearLayout>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/buttonsLayout" />

</RelativeLayout>

Обратите внимание на android:layout_above и android:layout_alignParentBottom="true" заданные для ListView. Эти аттрибуты используется внутри RelativeLayout
Если я правильно понял, то ваш код должен выглядеть примерно так:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="#FFFFFF"
        android:id="@+id/marina"
        android:padding="10dp" >

        <LinearLayout
            android:id="@+id/marina"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:background="#FF756C"
            android:gravity="center" >

            <Button
                android:id="@+id/marinaButton1"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:text="РЕКОМЕНДАЦИИ"
                android:background="#FF756C"
                android:fontFamily="sans-serif-thin"
                android:textColor="#FCFCFC" />

            <Button
                android:id="@+id/marinaButton1"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:fontFamily="sans-serif-thin"
                android:textColor="#FCFCFC"
                android:background="@drawable/settings49"
                android:layout_marginRight="10dp" />

        </LinearLayout>

        <Button
            android:layout_height="40dp"
            android:layout_width="40dp"
            android:id="@+id/marinaButton1"
            android:fontFamily="sans-serif-thin"
            android:textColor="#FCFCFC"
            android:background="@drawable/search100"
            android:layout_marginLeft="30dp"
            android:gravity="right" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/marinaLinearPlay"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:background="#FF5959"
        android:gravity="left|center" >

        <Button
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:background="@drawable/play105" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Винтаж  -  АМСТЕРДАМ"
            android:layout_marginLeft="15dp"
            android:fontFamily="sans-serif-thin" />

        <Button
            android:layout_width="33dp"
            android:layout_height="30dp"
            android:layout_marginLeft="100dp"
            android:background="@drawable/microsoft8" />

    </LinearLayout>

    <ListView
        android:id="@+id/marinaListView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/marina"
        android:layout_above="@id/marinaLinearPlay" >

</RelativeLayout>

И убедительная просьба, форматируйте свой код. Если вы используете Eclipse, Выделите весь текст комбинацией клавиш Ctrl+A а затем форматируйте комбинацией клавиш Ctrl+I

2
  • Спасибо, работает, только я не совсем понял. layout_below устанавлюет элемент ниже указанного а layout_above выше. Но я так и сделал. У меня ListView ниже id/marina а id/marinaLinearPlay ниже ListView. Почему моя разметка не работает?
    – user186301
    29 авг 2015 в 18:17
  • @user186301, это потому, что в RelativeLayout позиционирование абсолютно, т.е. если не задавать layout_below и (или) layout_above, то все элементы будут расположены вверху слева, перекрывая друг друга. В LinearLayout за построение друг на друге отвечает обязательный параметр orientation
    – PhoEn-X
    30 авг 2015 в 16:48

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.