1

I have a layout which contains a TextView and a CheckBox, and this looks as expected on my Galaxy Nexus (4.2.2):

Galaxy Nexus, default CheckBox style

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:

Galaxy S3, default CheckBox style

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 S3, custom CheckBox

Galaxy Nexus:

Galaxy Nexus, custom CheckBox

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.

warbi
  • 2,725
  • 2
  • 20
  • 26

2 Answers2

0

Instead of using a separate CheckBox and TextView, you can do this (the checkbox will appear on the left and the text will be padded 10dip to the right):

<CheckBox
   android:id="@+id/checkBox1"
   android:layout_height="wrap_content"
   android:layout_width="wrap_content"
   android:drawableLeft="@android:color/transparent"
   android:drawablePadding="10dp"
   android:text="Some Text"/>

The trick is to set colour to transparent for android:drawableLeft and assign a value for android:drawablePadding. Also, transparency allows you to use this technique on any background colour without the side effect - like colour mismatch.

Or

You can check this out.

ChuongPham
  • 4,761
  • 8
  • 43
  • 53
  • I'm not really sure how this would help - the drawable goes to the left of the text/right of the checkbox itself which, if anything, would increase the distance between the two. The CheckedTextView is interesting, thanks for the link, I'd not spotted that before. However the design I have calls for the text to be to the left of the checkbox. – warbi Oct 07 '13 at 09:12
  • @warbi: No problem. The CheckedTextView will be what you want. :) – ChuongPham Oct 13 '13 at 13:37
  • Sorry, I meant that it's interesting but it's not suitable as my check box needs to be to the right of the text - the CheckedTextView would basically give me the same functionality as a checkbox, but give me the option of not having to have an actual "box", yes? :-/ – warbi Oct 13 '13 at 21:08
  • Yes and no. I don't have a screendump of the CheckedTextView to post here, but perhaps this [link](https://www.google.com.au/search?q=CheckedTextView+images&lr=&as_qdr=all&tbm=isch&tbo=u&source=univ&sa=X&ei=1exbUr-yHefOiAfyzoCwDQ&ved=0CC4QsAQ&biw=973&bih=699&dpr=1) can give you some ideas on using the CheckedTextView component in your apps. – ChuongPham Oct 14 '13 at 13:14
0

had the same issue with an galaxy s2. Tested at the Samsung Remote Test Lab with the Result, that also the Android version is relevant. Seems that Samsung has fixed it on newer Versions.

    if (Build.MANUFACTURER.equals("samsung") && Build.MODEL.startsWith("GT-") && Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
a2hur
  • 167
  • 1
  • 1
  • 11