2

我想在 listview 的上方添加 imageview。我知道在列表视图中添加部分听众。但我只是想节省时间,所以我使用图像视图作为列表视图标题而不是使用 addSectionHeader。不幸的是,我只是坚持使用一些 xml 属性。我的列表视图中的图像叠加。实际上图像应该在列表的上面。查看我的 xml 布局。谢谢。

<?xml version="1.0" encoding="utf-8"?>

错误

4

3 回答 3

1

使用相对布局来获得关于或低于列表视图的视图。

您可以告诉视图与顶部、底部、左侧或右侧对齐,然后留出边距为其他视图腾出空间。

例如,如果您想要列表视图下方的图像,您可以将列表视图与父视图对齐,并为列表视图分配底部边距。然后将图像视图与父底部对齐,列表视图的边距将为它腾出空间。

希望这是有道理的。

编辑:

这是一些代码:我只是在脑海中写了这个,所以验证标签属性,但应该给你这个想法。

<?xml version="1.0" encoding="utf-8"?>  
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent" >
    <ListView
        android:id="@+id/list"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_marginBottom="50dp"
        android:layout_alignParentTop="true" />
    <TextView
        android:text="Some text"
        android:gravity="center"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_alignParentBottom="true" />  
</RelativeLayout>
于 2011-03-21T10:51:58.873 回答
1

此链接与您的问题EditText won't display above ListView相同

于 2011-03-21T10:58:25.810 回答
1

试试这个代码:​

TextView tv1=new TextView(context);
Resources res=getResources();
Drawable d1=res.getDrawable(R.drawable.YourImage);
tv1.setBackgroundDrawable(d1);
ListView.addHeaderView(tv1);
于 2011-03-21T11:00:20.907 回答