如何在一个Android的ListView的结尾显示一个按钮结尾、按钮、如何在、ListView

2023-09-12 04:04:56 作者:你若离去.后会无妻

我想在一个Android的列表视图的末尾显示一个按钮。我怎样才能做到这一点?

我不希望它坚持采用活动底 alignparentbottom =真正的。使用 layout_below 对我也不起作用。

我目前的XML:

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=横向
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:背景=@可绘制/ main_bg>

    <的LinearLayout
        的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:方向=垂直
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT>

        <的ListView
            机器人:ID =@ + ID / Android的:清单
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:drawSelectorOnTop =假
            机器人:cacheColorHint =#ff6a00
            机器人:分隔=#ff8f40
            机器人:dividerHeight =1像素/>

    < / LinearLayout中>

    < RelativeLayout的
        的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:layout_width =FILL_PARENT
            机器人:layout_height =50SP
        机器人:后台=#676767
        机器人:方向=垂直>

        <按钮
            机器人:layout_width =100像素
            机器人:layout_height =WRAP_CONTENT
            机器人:ID =@ + ID / btnGetMoreResults
            机器人:layout_marginLeft =10px的
            机器人:文本=更多/>

    < / RelativeLayout的>

< / RelativeLayout的>
 

解决方案

您可能需要使用ListView#addFooterView()添加查看在底部的的ListView

Android ListView 显示最后一行

I want to show a button at the end of an Android list view. How can I achieve this?

I don't want to stick it to the activity bottom using alignparentbottom="true". Using layout_below does not work for me either.

My current XML:

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/main_bg">

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <ListView
            android:id="@+id/android:list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:drawSelectorOnTop="false"
            android:cacheColorHint="#ff6a00"
            android:divider="#ff8f40"
            android:dividerHeight="1px" />

    </LinearLayout>

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
            android:layout_height="50sp"
        android:background="#676767"
        android:orientation="vertical">

        <Button
            android:layout_width="100px"
            android:layout_height="wrap_content"
            android:id="@+id/btnGetMoreResults"
            android:layout_marginLeft="10px"
            android:text="Get more" />

    </RelativeLayout>

</RelativeLayout>

解决方案

You may want to use ListView#addFooterView() to add a View at the bottom of the ListView.