Android布局:在TextView和Android:drawableStart——设置图标的大小?
Lars Vogel关于SQLite、own ContentProvider和Loader的教程对ToDo项列表使用以下布局(检查,Android布局:在TextView和Android:drawableStart——设置图标的大小?,android,android-layout,android-widget,textview,Android,Android Layout,Android Widget,Textview,Lars Vogel关于SQLite、own ContentProvider和Loader的教程对ToDo项列表使用以下布局(检查,ToDo_row.xmllayout文件): 即,使用了drawableStart而不是ImageView。相关的android:layout_marginLeft和android:drawable padding似乎工作正常 然而,我不知道是否有可能告诉大小的拉丝。ImageView解决方案使用了android:layout\u width/height属性来告知
ToDo_row.xml
layout文件):
即,使用了drawableStart
而不是ImageView
。相关的android:layout_marginLeft
和android:drawable padding
似乎工作正常
然而,我不知道是否有可能告诉大小的拉丝。ImageView
解决方案使用了android:layout\u width
/height
属性来告知想要的图标尺寸。只有TextView
的解决方案和android:drawable…
是否有类似的功能
谢谢,Petr不幸的是,无法使用
xml
更改TextView
的可绘制大小。它只能用Java
完成
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);
最终线性布局布局=;
最终TextView标签=(TextView)layout.findviewbyd(R.id.label);
最终浮点密度=getResources().getDisplayMetrics().density;
final Drawable Drawable=getResources().getDrawable(R.Drawable.rementer);
最终整数宽度=数学圆(30*密度);
最终整数高度=数学圆(24*密度);
可拉伸立根(0,0,宽度,高度);
label.setCompoundDrawables(drawable,null,null,null);
<?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>
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);