I created a android widget with a icon that shows a number in the right top corner in a little white circle. Now if my value is one character the value is right in the middle of the little whit circle. But when the value is 2 characters it is not right in the middle anymore.
What is try to do is if my value is more then 1 character then i want to change the left margin of the textview so the value is in the center of th white circle that is part of the icon.
I tried all ready with the
RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.widget);
updateViews.setInt(R.id.Value, "setMargins", 10);
But that gives a exception.
Is there a way of changing the left margin in a widget on runtime ???
My layout file looks like:
<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"
/>
add to your textview in xml
Your text will always be in center.