Android 具有表布局的listview

Android 具有表布局的listview,android,listview,tablelayout,Android,Listview,Tablelayout,我正在开发一个活动,其中我使用列表视图和表布局。 我想在列表视图中显示图像和文本,但问题是图像的显示顺序与列表顺序稍有出入,如 img1 text1 img1 text1 img2 text2 and i want this img2 text2 img3 text3 img3 text3

我正在开发一个活动,其中我使用列表视图和表布局。 我想在列表视图中显示图像和文本,但问题是图像的显示顺序与列表顺序稍有出入,如

 img1        text1                              img1    text1
  img2       text2     and i want this          img2    text2
 img3        text3                              img3    text3
 img4        text4                              img4    text4
 img5        text5                              img5    text5
这边。。那么,您知道列表视图或图像视图的属性是什么吗?然后请评论

list_row.xml

    <?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="?android:attr/listPreferredItemHeight"
    android:background="#ffffff"
    android:padding="6dip" >

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#ffffff"
        android:stretchColumns="*" >

        <TableRow>

            <ImageView
                android:id="@+id/icon"
                android:layout_gravity="left"
                android:background="#ffffff"
                android:padding="2dip" />

            <TextView
                android:id="@+id/description"
                android:background="#ffffff"
                android:padding="2dip"
                android:singleLine="true"
                android:textColor="#000000"
                android:textSize="12sp" />
        </TableRow>
    </TableLayout>

</LinearLayout>

main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#ffffff">



    <ListView
        android:id="@+id/android:list"
        android:background="#ffffff"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:dividerHeight="1dip"/>
</LinearLayout>

试试这个

<?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="?android:attr/listPreferredItemHeight"
    android:background="#ffffff"
    android:orientation="horizontal"
    android:padding="6dip" >

            <ImageView
                android:id="@+id/icon"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:src="@drawable/ic_launcher"
                android:layout_gravity="center"
                android:background="#ffffff" />

            <TextView
                android:id="@+id/description"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:background="#ffffff"
                android:layout_weight="0.5"
                android:singleLine="true"
                android:text="text"
                android:layout_gravity="center"
                android:gravity="center"
                android:textColor="#000000"
                android:textSize="12sp" />

</LinearLayout>

在您的表格布局中尝试以下代码

<TableRow>

        <ImageView
            android:id="@+id/icon"
            android:layout_gravity="left"
            android:background="#ffffff"
            android:padding="2dip" 
            android:layout_gravity="center"/>

        <TextView
            android:id="@+id/description"
            android:background="#ffffff"
            android:padding="2dip"
            android:singleLine="true"
            android:textColor="#000000"
            android:textSize="12sp"
            android:gravity="center"
            android:layout_gravity="center" />
    </TableRow>

你可以用这个

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:background="#c0c0c0" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center|left"
        android:layout_marginLeft="20dp"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Large Text"
         android:layout_gravity="center|left"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

</LinearLayout>

**项目列表.xml**

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="@color/WHITE_BACKGROUND"
 android:orientation="vertical" >

<TableLayout
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:stretchColumns="1" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TableLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_span="2"
                android:stretchColumns="1" >


                    <TextView
                        android:id="@+id/Text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="3sp"
                        android:layout_marginTop="5dp"
                        android:ellipsize="end"
                        android:maxLines="1"
                        android:text="Address"
                        android:textColor="@color/text_color"
                        android:textStyle="normal|italic" />

            </TableLayout>

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_gravity="center_horizontal|center_vertical"
                android:padding="2dp" >

                <ImageView
                    android:id="@+id/featureListImageRight"
                    android:layout_width="15dp"
                    android:layout_height="15dp"
                    android:layout_centerInParent="true"
                    android:layout_gravity="right"
                    android:scaleType="fitXY"
                    android:src="@drawable/icon_right" />
            </RelativeLayout>
        </TableRow>
    </TableLayout>

</RelativeLayout>


**Main.xml**


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/WHITE_BACKGROUND"
    android:orientation="vertical" >
 <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0">

<ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/WHITE_BACKGROUND" >

 </ListView>
    </LinearLayout>
</RelativeLayout>

**Main.xml**

使用上述代码。根据您的要求,完全不需要Tablelayout。@autocrat您不需要要求。@Rain ya我已经试过了。你想在imageView中显示结果吗?我不认为你已经尝试了这段代码,因为只要看看你的imageView标签。。它包含2次相同的参数,即
android:layout\u gravity
。它的ohk..~!当你要帮助别人时要小心@Tamilany可以根据需要在Jigs Patel设置重力