android - 带有表格布局的 ListView

标签 android listview tablelayout

我正在开发一项 Activity ,其中我使用带有表格布局的 ListView 。 我想在那个 ListView 中显示图像和文本,但问题是图像的显示顺序有点乱,比如

 img1        text1                              img1    text1
  img2       text2     and i want this          img2    text2
 img3        text3                              img3    text3
 img4        text4                              img4    text4
 img5        text5                              img5    text5

这样..那么关于 ListView 或 ImageView 的属性以正确设置它的任何想法?然后请评论...

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>

ma​​in.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>

关于android - 带有表格布局的 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19977324/

相关文章:

android - 在 TableLayout 中对齐列

html - 桌面和移动 View 的不同表结构

python-sphinx - 如何在不使用 RST 表格格式的情况下在 reStructuredText 中生成表格输出?

带有按钮 View 问题的Android TranslateAnimation

java - 划掉文字

Android _ 任务 ':app:packageAllDebugClassesForMultiDex' _ AbstractDateTime.class 失败?

android - 如何在 Android 的 getView() 函数中取消从隐藏项执行的 AsyncTask?

java - 错误 : getText must be called from the UI thread

android - 数据库全局实例

android - 使用 EditText Android 过滤 Json ListView