Lars Vogel 的教程SQLite,自己的ContentProvider和Loader对待办事项列表使用以下布局(检查http://www.vogella.com/articles/AndroidSQLite/article.html#todo_layout 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
by the 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>
IE。这drawableStart
被用来代替ImageView
。相关的android:layout_marginLeft
and android:drawablePadding
似乎工作正常。
但是,我不知道是否可以告诉可绘制的大小。这ImageView
解决方案使用了android:layout_width
/height
属性来告诉所需的图标尺寸。有没有类似的东西TextView
-唯一的解决方案和android:drawable...
?
谢谢,彼得
不幸的是,无法更改TextView
的可绘制尺寸使用xml
。可以用以下方法完成Java
only.
final LinearLayout layout = <get or create layou here>;
final TextView label = (TextView) layout.findViewById(R.id.label);
final float density = getResources().getDisplayMetrics().density;
final Drawable drawable = getResources().getDrawable(R.drawable.reminder);
final int width = Math.round(30 * density);
final int height = Math.round(24 * density);
drawable.setBounds(0, 0, width, height);
label.setCompoundDrawables(drawable, null, null, null);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)