【发布时间】:2013-02-26 17:19:12
【问题描述】:
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 替换为 TextView 的 drawable 属性。我尝试了以下布局定义:
<?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 属性来告知所需的图标尺寸。 TextView-only 解决方案和android:drawable... 有什么相似之处吗?
谢谢,彼得
【问题讨论】:
标签: android android-layout android-widget textview