Lars Vogel 的关于SQLite、自己的 ContentProvider 和 Loader的教程使用以下布局作为 ToDo 项目列表(查看http://www.vogella.com/articles/AndroidSQLite/article.html#todo_layout,todo_row.xml布局文件):
<?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="wrap_content" >
<ImageView
android:id="@+id/icon"
android:layout_width="30dp"
android:layout_height="24dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:src="@drawable/reminder" >
</ImageView>
<TextView
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:lines="1"
android:text="@+id/TextView01"
android:textSize="24dp"
>
</TextView>
</LinearLayout>
到现在为止还挺好。它工作得很好。Android 开发者工具 (Eclipse) 建议将ImageView. 的drawable属性替换为TextView. 我尝试了以下布局定义:
<?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="wrap_content" >
<TextView
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="4dp"
android:drawablePadding="8dp"
android:drawableStart="@drawable/reminder"
android:lines="1"
android:text="@+id/TextView01"
android:textSize="24sp"
>
</TextView>
</LinearLayout>
即drawableStart使用的是而不是ImageView。相关的android:layout_marginLeft,android:drawablePadding似乎工作正常。
但是,我不知道是否可以告诉drawable的大小。该ImageView解决方案使用android:layout_width/height属性来告诉想要的图标尺寸。-onlyTextView解决方案和android:drawable...?
谢谢,彼得