I have a layout which contains a TextView and a CheckBox, and this looks as expected on my Galaxy Nexus (4.2.2):
However when viewing on a Galaxy S3 and S2, I get some odd padding to the top, right and bottom of the CheckBox which is messing up the horizontal alignment of the whole subview:
The XML layout:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_vert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<LinearLayout
android:id="@+id/ll_horz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="Some Text"
android:textSize="14sp" />
<CheckBox
android:id="@+id/cb"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
It's even more obvious if I used a selector for a custom checkbox resource (which I'm ultimately trying to do):
<CheckBox
android:id="@+id/cb"
android:gravity="center"
android:button="@drawable/selector_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Galaxy S3:
Galaxy Nexus:
Anyone else experienced this? Obviously the gravity="center" appears to have no effect on TouchWiz...
EDIT 10-SEP-2013 -
I hacked in a fix
if (android.os.Build.MANUFACTURER.equals("samsung") && android.os.Build.MODEL.startsWith("GT-")) {
LinearLayout llHorz = (LinearLayout)view.findViewById(R.id.ll_horz);
llHorz.setPadding(Math.round(getResources().getDisplayMetrics().density * 20f), llHorz.getPaddingTop(), llHorz.getPaddingRight(), llHorz.getPaddingBottom());
}
This is less than ideal but it serves its purpose for now.