如何在动态生成列表(列表视图)的同时在屏幕底部放置一个按钮?

时间:2015-04-13 17:48:05

标签: android xml

List-Row.xml:文件一行的结构。 所以,我想添加一个按钮来添加一个新用户,无论代码中添加了多少行,它都会保持在屏幕的底部。

<?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="wrap_content"
    android:background="@drawable/list_selector"
    android:orientation="horizontal"
    android:padding="5dip" >

<!--  ListRow Left sied Thumbnail image -->

    <LinearLayout android:id="@+id/thumbnail"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="3dip"
    android:layout_alignParentLeft="true"
    android:background="@drawable/image_bg"
    android:layout_marginRight="5dip">

    <ImageView
        android:id="@+id/list_image"
        android:layout_width="50dip"
        android:layout_height="50dip"
        android:src="@drawable/account_image"/>

</LinearLayout>

<!-- Title Of Song-->
<TextView
    android:id="@+id/account_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/thumbnail"
    android:layout_toRightOf="@+id/thumbnail"
    android:text="Account one"
    android:textColor="#040404"
    android:typeface="sans"
    android:textSize="15dip"
    android:textStyle="bold"/>

<!-- Rightend Arrow -->
<ImageView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/arrow"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"/>

3 个答案:

答案 0 :(得分:0)

<LinearLayout android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">
<ListView android:id="@android:id/mylist"
      android:layout_height="0dip"
      android:layout_width="match_parent"
      android:layout_weight="1" />
<Button android:id="@+id/mybtn" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

</LinearLayout>

答案 1 :(得分:0)

https://stackoverflow.com/a/10083342/4784128

这对我来说效果最好。使用android放置相对于列表的按钮:layout_alignParentBottom =&#34; true&#34;做了诀窍

答案 2 :(得分:0)

尝试这样的事情,

       <RelativeLayout   
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ignoreGravity="@+id/addNewUserButton"
            android:descendantFocusability="blocksDescendants">

            <ListView
                android:id="@+id/your_listview"
                />

            <RelativeLayout
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentRight="true">

                    <ImageButton
                        android:id="@+id/addNewUserButton"
                        android:background=""  
                        android:paddingTop="10dp"
                        android:paddingRight="12dp"
                        android:paddingBottom="12dp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"/>
                </RelativeLayout>
        </RelativeLayout>