I have a TextView in a layout defined like so...
<TextView
android:id="@+id/startworkout"
android:layout_width="110dip"
android:layout_height="30dip"
android:background="@drawable/shape_doworkout_blue_white"
android:ellipsize="end"
android:gravity="center"
android:paddingBottom="4dip"
android:paddingTop="4dip"
android:singleLine="true"
android:text="Do workout"
android:textColor="@color/blue"
android:textSize="14sp" />
The background drawable is defined like so...
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="@color/blue" />
<padding
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp" />
<corners
android:bottomLeftRadius="15dip"
android:bottomRightRadius="15dip"
android:topLeftRadius="15dp"
android:topRightRadius="15dip" />
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
<corners
android:bottomLeftRadius="15dip"
android:bottomRightRadius="15dip"
android:topLeftRadius="15dp"
android:topRightRadius="15dip" />
<solid android:color="@color/white" />
</shape>
</item>
</layer-list>
I have another drawable called shape_doworkout_green_white which is the exact same as the above drawable, but @color/blue is replaced with @color/green.
When this TextView displays on screen, everything is how I want it. Most notably, the text is centered.
However, if I update the background resource to my other drawable (or even the same blue drawable), the text becomes slightly off centered.
holder.txtStartWorkout.setBackgroundResource(R.drawable.shape_doworkout_green_white);
holder.txtStartWorkout.setTextColor(getResources().getColor(R.color.green));
holder.txtStartWorkout.setText("Completed");
I'm not sure why this is happening. Ideas?
0 comments:
Post a Comment