![](/img/trans.png)
[英]Android sticky-footer: Align footer view to table, until it reaches screen size, then become fixed.at the bottom
[英]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.