Как переместить включенный макет в нижнюю часть экрана?

У меня есть макет с именем footer.xml, который позже будет включен в несколько макетов. Footer.xml выглядит следующим образом:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/bottomMenu"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:orientation="horizontal"
    android:layout_alignParentBottom="true"
    android:background="@drawable/bg_gradation"
    android:weightSum="1" >
*** STUFF GOES HERE ***
</LinearLayout>

После этого файл Footer.xml будет включен в другой макет следующим образом.

<?xml version="1.0" encoding="utf-8"?>
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/backrepeat">

    <!-- As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions. -->
    <LinearLayout
       android:id="@+id/content_frame"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:orientation="vertical"
       android:layout_marginBottom="0dp"
       android:weightSum="1">
        <ListView
            android:id="@+id/chatListView"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:divider="#00000000"
            android:scrollbars="none"
            android:dividerHeight="1dp"
            android:layout_weight=".80"/>
        <LinearLayout
            android:id="@+id/chatBar"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight=".13"
            android:orientation="horizontal"
            android:background="#242424"
            android:weightSum="1">
        </LinearLayout>
    </LinearLayout>
    <include layout="@layout/footer"/>

    <!-- android:layout_gravity="start" tells DrawerLayout to treat
         this as a sliding drawer on the left side for left-to-right
         languages and on the right side for right-to-left languages.
         The drawer is given a fixed width in dp and extends the full height of
         the container. A solid background is used for contrast
         with the content view. -->
    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#111"/>
</android.support.v4.widget.DrawerLayout>

Так как я хочу, чтобы файл footer.xml находился внизу экрана, я использую android:layout_gravity="bottom", он отображается правильно, если смотреть с точки зрения файла footer.xml.

Однако, когда я пытаюсь увидеть его с других макетов, он выдает ошибку, которая говорит:

java.lang.UnsupportedOperationException (Error Log does not show helpful information at all).

EDIT 1 Это лучшее сообщение об ошибке, которое я мог получить.. (я не могу скопировать и вставить текст журнала)

ошибка журнала

ИЗМЕНИТЬ 2 ЕСЛИ я включаю свой макет таким образом:

<LinearLayout
    android:layout_weight="1"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <include layout="@layout/footer"
        android:id="@+id/footer"/>
</LinearLayout>

Он отображает так, как я хочу, в редакторе eclipse. Однако, когда я пытаюсь запустить его на Android, я получаю следующую ошибку:

java.lang.IllegalStateException: Child android.widget.LinearLayout{a72d4938 V.E..... ......ID 0,0-0,0 #7f0a005c app:id/bottomMenu} at index 1 does not have a valid layout_gravity - must be Gravity.LEFT, Gravity.RIGHT or Gravity.NO_GRAVITY

и если я отредактировал свой footer.xml следующим образом:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/bottomMenu"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" <---- not android:layout_gravity="bottom"
    android:background="@drawable/bg_gradation"
    android:weightSum="1" >

мой нижний колонтитул заполнил бы весь экран сверху вниз.

Кто-нибудь может мне с этим помочь? Спасибо..


person Jeremy    schedule 08.01.2014    source источник


Ответы (1)


Поместите вас linearLayout и нижний колонтитул внутри относительного макета

   <include
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        layout="@layout/activity_main" />

XML:

<?xml version="1.0" encoding="utf-8"?>
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/backrepeat">

    <!-- As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions. -->
    <RelativeLayout android:layout_width="match_parent"
       android:layout_height="match_parent">
    <LinearLayout
       android:id="@+id/content_frame"
       android:layout_above="@+id/footer"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:orientation="vertical"
       android:layout_marginBottom="0dp"
       android:weightSum="1">
        <ListView
            android:id="@+id/chatListView"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:divider="#00000000"
            android:scrollbars="none"
            android:dividerHeight="1dp"
            android:layout_weight=".80"/>
        <LinearLayout
            android:id="@+id/chatBar"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight=".13"
            android:orientation="horizontal"
            android:background="#242424"
            android:weightSum="1">
        </LinearLayout>
    </LinearLayout>
    <include layout="@layout/footer"     android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"/>
    </RelativeLayout>
    <!-- android:layout_gravity="start" tells DrawerLayout to treat
         this as a sliding drawer on the left side for left-to-right
         languages and on the right side for right-to-left languages.
         The drawer is given a fixed width in dp and extends the full height of
         the container. A solid background is used for contrast
         with the content view. -->
    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
person vipul mittal    schedule 08.01.2014
comment
введите код, этого недостаточно, и у вас возникла проблема откуда-то еще - person DropAndTrap; 08.01.2014