簡體   English   中英

列表視圖下方的頁腳固定在屏幕底部

[英]Footer below list view fixed at the bottom of the screen

我試圖在我的列表視圖下面放一個頁腳。

這是怎么做的。

<?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/white"
android:orientation="vertical" >

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:divider="#BE6D79"
    android:dividerHeight="3dp" />

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="30dp"
    android:background="@color/darkDetna"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/contactBtn"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_weight="1"
        android:background="@drawable/listselector"
        android:paddingRight="0dip"
        android:text="Contact" />

    <Button
        android:id="@+id/faq"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_weight="1"
        android:background="@drawable/listselector"
        android:padding="0dip"
        android:text="Terms And Conditions" />

    <Button
        android:id="@+id/feedback"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_weight="1"
        android:background="@drawable/listselector"
        android:padding="0dip"
        android:text="Feedback  " />

    <Button
        android:id="@+id/fullSIte"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_weight="1"
        android:background="@drawable/listselector"
        android:padding="0dip"
        android:text="Full Site" />
</LinearLayout>
</LinearLayout>

這里

但是問題是列表內容很小,或者頁腳ll在列表視圖下方只有一個列表項。

我希望頁腳固定在屏幕底部。

在此先感謝您的時間和幫助。

更好地使用RelativeLayout

解釋實現:

  • 添加頁腳視圖以使其在屏幕底部對齊android:layout_alignParentBottom="true"
  • 然后在頁腳布局android:layout_above="@+id/LinearLayout1"上方添加listview
  • 使您的列表視圖填充屏幕android:layout_width="fill_parent"android:layout_height="fill_parent"

更改您的代碼:

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

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/LinearLayout1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_weight="1"
        android:divider="#BE6D79"
        android:dividerHeight="3dp" />

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/LinearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="30dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:background="@color/darkDetna"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/contactBtn"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_weight="1"
            android:background="@drawable/listselector"
            android:paddingRight="0dip"
            android:text="Contact" />

        <Button
            android:id="@+id/faq"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_weight="1"
            android:background="@drawable/listselector"
            android:padding="0dip"
            android:text="Terms And Conditions" />

        <Button
            android:id="@+id/feedback"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_weight="1"
            android:background="@drawable/listselector"
            android:padding="0dip"
            android:text="Feedback  " />

        <Button
            android:id="@+id/fullSIte"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_weight="1"
            android:background="@drawable/listselector"
            android:padding="0dip"
            android:text="Full Site" />
    </LinearLayout>

</RelativeLayout>

您可以使用RelativeLayout而不是LinearLayout,然后使用android:layout_alignParentBottom="true"將視圖添加到RelativeLayout的底部

   <?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/white"
    android:orientation="vertical" >

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:divider="#BE6D79"
    android:dividerHeight="3dp" />

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="30dp"
    android:background="@color/darkDetna"
    android:orientation="horizontal"
    android:layout_alignParentBottom="true" >

    <Button
        android:id="@+id/contactBtn"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_weight="1"
        android:background="@drawable/listselector"
        android:paddingRight="0dip"
        android:text="Contact" />

    <Button
        android:id="@+id/faq"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_weight="1"
        android:background="@drawable/listselector"
        android:padding="0dip"
        android:text="Terms And Conditions" />

    <Button
        android:id="@+id/feedback"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_weight="1"
        android:background="@drawable/listselector"
        android:padding="0dip"
        android:text="Feedback  " />

    <Button
        android:id="@+id/fullSIte"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_weight="1"
        android:background="@drawable/listselector"
        android:padding="0dip"
        android:text="Full Site" />
</LinearLayout>

如果您不想使用RelativeLayout,則可以在第二個linearlayout上設置android:layout_gravity="bottom"

您可以將RelativeLayout用作版式的根視圖。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM