我创建了一个带有图标的Android小部件,该图标在右上角显示一个数字,表示一个小小的白色圆圈。现在,如果我的价值是一个角色,那么价值就在小白衣圈子中间。但是当这个值是2个字符时,它就不再适合了。Android小部件在运行时更改边距
试图做的是,如果我的值超过1个字符,那么我想更改textview的左边距,使得值位于图标一部分的白色圆圈的中心。
我尝试了所有准备与
RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.widget);
updateViews.setInt(R.id.Value, "setMargins", 10);
但是,给出了一个例外。 有没有办法在运行时改变widget的左边距?
我的布局文件的样子:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/widget_alarm"
android:id="@+id/imageAlarm"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"
/>
<TextView
android:id="@+id/alarmCount"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="22dip"
android:layout_marginLeft="58dip"
android:text="0"
android:textColor="#000000"
/>
我添加了布局文件。 我使用的是有一个裕度左侧58倾角。如果我的文本是2个字符或更多,我想将我的填充更改为像56 dip或les这样的文本,因此文本更多地移动到左侧。 – 2012-02-07 07:55:18