【问题标题】:How to make header and sticky footer in layout xml android如何在布局xml android中制作页眉和粘性页脚
【发布时间】:2012-09-27 22:07:36
【问题描述】:

我试图使用相对布局,但标题变成了文本前面。所以一切都朝着错误的方向发展。 我的应用程序屏幕如下所示:

我还想添加页脚,但每次尝试都会失败。我很确定我的 xml 布局中的所有宽度和高度都可以。

这是我的 xml:

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

    <LinearLayout
        android:id="@+id/header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/item1"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight=".25"
            android:height="30dip"
            android:text="@string/item1" />

        <TextView
            android:id="@+id/item2"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight=".25"
            android:height="30dip"
            android:text="@string/item2" />

        <TextView
            android:id="@+id/item3"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight=".25"
            android:height="30dip"
            android:text="@string/item3" />

        <TextView
            android:id="@+id/item4"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight=".25"
            android:height="30dip"
            android:text="@string/item4" />
    </LinearLayout>

    <!-- List Divider -->

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="?android:attr/listDivider" />

    <!-- ListView (grid_items) -->

    <LinearLayout
        android:id="@+id/layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <ListView
            android:id="@+id/listview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
         </ListView>

    </LinearLayout>

</LinearLayout>

请给我任何建议。我认为相对布局会是个好主意,但我还不太了解。

【问题讨论】:

    标签: android android-layout header sticky-footer


    【解决方案1】:

    1/ 为'main'使用RelativeLayout。

    2/ 将属性 android:layout_alignParentTop="true" 添加到 'header'。

    3/ 移除id为'layout'的LinearLayout,不需要了。

    4/ 将页脚添加到 XML 的末尾。指定其 id 时,使用@id 而不是@+id。给它一个属性 android:layout_alignParentBottom="true"。

    5/ 给ListView添加如下属性:

    android:layout_below="@id/header"
    android:layout_above="@+id/the_id_you_give_the_footer"
    

    【讨论】:

      猜你喜欢
      • 2012-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-08
      • 2011-12-18
      • 2018-09-11
      相关资源
      最近更新 更多