I think I'm not seeing an error in one of my layouts. I want to display a Checkbox and and a border around it.
I generated the images using the Android Holo Colors Generator
I tried to add a shape to the checkbox, which worked fine on a Nexus 4, but did not display the button at all on any other device, so I added a dummy layout:
Layout:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5sp"
android:layout_marginTop="3sp"
android:background="@drawable/shape_button" >
<CheckBox
android:id="@+id/check"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:button="@drawable/btn_radio_holo_dark_hm" />
</LinearLayout>
shape:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/transparent"/>
<stroke
android:width="1px"
android:color="@color/gray" />
<corners
android:bottomLeftRadius="5sp"
android:bottomRightRadius="5sp"
android:topLeftRadius="5sp"
android:topRightRadius="5sp" />
</shape>
Now I get this:

I tried setting minWidth depending on mdpi/hdpi/xhdpi but the button never looks centered on every device. fill_parent/wrap_content does not result in any change, also moving the button inside the layout.
Any suggestions on what has gone wrong here?
change your outer layout to a RelativeLayout and set centerInParent=true for checkbox
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5sp"
android:layout_marginTop="3sp"
android:background="@drawable/shape_button"
android:padding="2sp">
<CheckBox
android:id="@+id/check"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:button="@drawable/btn_radio_holo_dark_hm"
android:layout_centerInParent="true/>
</RelativeLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With