0

我正在尝试使用 3 层的布局。我正在使用 3 个线性布局,其中一个是列表视图,但我的底部线性布局没有出现在屏幕上。

我需要: 在顶部:水平线性布局 | 居中:Listview | 底部:水平线性布局

我正在使用这段代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/BackGroundColor"
    android:orientation="vertical"
    android:scaleType="center" >

    <LinearLayout
        android:id="@+id/titleLayout"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:background="@color/titleBgColor"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/filterButton"
            android:layout_width="33dp"
            android:layout_height="33dp"
            android:layout_gravity="left"
            android:layout_weight="0"
            android:background="@drawable/filtericon" />

        <TextView
            android:id="@+id/sectionTitle"
            style="@style/sectionTitle"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="(blank)" />

        <Button
            android:id="@+id/addCatButton"
            android:layout_width="33dp"
            android:layout_height="33dp"
            android:layout_gravity="right"
            android:layout_weight="0"
            android:background="@drawable/effect_button_add_cat_click" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:divider="#b5b5b5"
            android:dividerHeight="1dp"
            android:listSelector="@drawable/listview_style_list_selector" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottomLayout"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:background="@color/titleBgColor"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/optionsButton"
            android:layout_width="33dp"
            android:layout_height="33dp"
            android:layout_gravity="left"
            android:layout_weight="0"
            android:background="@drawable/filtericon" />

        <TextView
            android:id="@+id/totalValue"
            style="@style/sectionTitle"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="66,00€&quot; />

        <Button
            android:id="@+id/savExpIncValues"
            android:layout_width="33dp"
            android:layout_height="33dp"
            android:layout_gravity="right"
            android:layout_weight="0"
            android:background="@drawable/effect_button_add_cat_click" />
    </LinearLayout>

</LinearLayout>

怎么了?谢谢

4

2 回答 2

1

我已经为你修复了布局。试试看:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/BackGroundColor"
    android:orientation="vertical"
    android:scaleType="center" >

    <LinearLayout
        android:layout_alignParentTop="true"
        android:id="@+id/titleLayout"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:background="@color/titleBgColor"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/filterButton"
            android:layout_width="33dp"
            android:layout_height="33dp"
            android:layout_gravity="left"
            android:layout_weight="0"
            android:background="@drawable/filtericon" />

        <TextView
            android:id="@+id/sectionTitle"
            style="@style/sectionTitle"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="(blank)" />

        <Button
            android:id="@+id/addCatButton"
            android:layout_width="33dp"
            android:layout_height="33dp"
            android:layout_gravity="right"
            android:layout_weight="0"
            android:background="@drawable/effect_button_add_cat_click" />
    </LinearLayout>

    <ListView
        android:layout_above="@+id/bottomLayout"
        android:layout_below="@+id/titleLayout"
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:divider="#b5b5b5"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/listview_style_list_selector"
         />

    <LinearLayout
        android:layout_alignParentBottom="true"
        android:id="@+id/bottomLayout"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:background="@color/titleBgColor"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/optionsButton"
            android:layout_width="33dp"
            android:layout_height="33dp"
            android:layout_gravity="left"
            android:layout_weight="0"
            android:background="@drawable/filtericon" />

        <TextView
            android:id="@+id/totalValue"
            style="@style/sectionTitle"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="66,00€" />

        <Button
            android:id="@+id/savExpIncValues"
            android:layout_width="33dp"
            android:layout_height="33dp"
            android:layout_gravity="right"
            android:layout_weight="0"
            android:background="@drawable/effect_button_add_cat_click" />
    </LinearLayout>

</RelativeLayout>
于 2013-07-28T19:00:07.560 回答
0

第二个布局的高度设置为 match_parent,将其更改为 wrap_content 或固定大小。但我强烈建议您使用 weight 属性以这种方式设置 3 个布局的高度:

    <!-- your first layout -->
    <LinearLayout
      android:id="@+id/titleLayout"
      android:layout_width="match_parent"
      android:layout_height="35dp"... >
    ... 
    </LinearLayout>

    <!-- your second layout -->
    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="1"
      android:orientation="vertical" >
    ...
    </LinearLayout>

    <!-- your third layout -->
    <LinearLayout
      android:id="@+id/bottomLayout"
      android:layout_width="match_parent"
      android:layout_height="35dp" ..>
    ...
    </LinearLayout>

还将所有 LinearLayout 方向设置为垂直。

于 2013-07-28T18:52:07.860 回答