如何在列表视图项之间使用图像?

时间:2014-09-13 15:48:55

标签: android image list listview

我是android新手。这是我的列表查看项目代码:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow>
    <ImageView
        android:id="@+id/img"
        android:layout_width="50dp"
        android:layout_height="50dp"/>
    <TextView
        android:id="@+id/txt"
        android:layout_width="wrap_content"
        android:layout_height="50dp" />
</TableRow>
</TableLayout>

我想在列表视图的顶部添加简单图像 请帮帮我

1 个答案:

答案 0 :(得分:0)

在调用ListView之前将ImageView对齐到顶部或放置ImageView。

如果您希望图片位于列表视图的顶部,请执行以下操作:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
         <ImageView
            android:id="@+id/img"
            android:layout_width="50dp"
            android:layout_height="50dp"/>
    </RelativeLayout>

    <ImageView
        android:id="@+id/img"
        android:layout_width="50dp"
        android:layout_height="50dp"/>
    <TextView
        android:id="@+id/txt"
        android:layout_width="wrap_content"
        android:layout_height="50dp" />
</TableRow>
</TableLayout>

如果您想在列表视图之前添加图像,请执行以下操作:

<ImageView
        android:id="@+id/img"
        android:layout_width="50dp"
        android:layout_height="50dp"/>

<ListView
          android:id="@+id/listview_row"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent">
     </ListView>