Android Text inside of ToggleButton wont center
I have a very unusual issue; I have a few ToggleButtons inside of a linear layout stacked horizontally. The text inside (textOn, textOff) of the buttons isn't centering, and after playing a bit with paddingLeft, I found that 15% of of each button on the right hand side is something of a 'dead area', meaning the text is wrapping when it hits it -- this would explain why it's not centering properly.
Here's the XML:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dip"
android:weightSum="1.5"
android:background="#0094d2"
android:orientation="horizontal">
<ToggleButton
android:id="@+id/button1"
android:layout_weight=".5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/off_white"
android:textStyle="bold"
android:textOn="Button On"
android:textOff="Button Off"
android:background="@drawable/toggle_states"/>
<ToggleButton
android:id="@+id/button2"
android:layout_weight=".5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/off_white"
android:textStyle="bold"
android:textOn="Button On"
android:textOff="Button Off"
android:background="@drawable/toggle_states"/>
<ToggleButton
android:id="@+id/button3"
android:layout_weight=".5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@开发者_如何学Ccolor/off_white"
android:textStyle="bold"
android:textOn="Button On"
android:textOff="Button Off"
android:background="@drawable/toggle_states"/>
</LinearLayout>
<View android:background="#999999" android:layout_height="1dip" android:id="@+id/divider" android:layout_below="@+id/buttons" android:layout_width="fill_parent"/>
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
android:divider="#cccccc"
android:dividerHeight="1dip"
android:layout_below="@+id/divider"
android:fadingEdge="none"/>
</RelativeLayout>
Link to Image, I'm too new so I can't add images yet ><
I've tried setting the gravity in the layout and buttons to center_horizontal as well.. obviously, it didn't help.
Any ideas?
I copied/pasted into eclipse and got:
I dont have your drawables, so cant look at them but i think that is your issue. Are you using 9 patch graphics for your button, if not have a look at this link: http://developer.android.com/guide/developing/tools/draw9patch.html
精彩评论