4

I am Working on Project with inside i want to Use custome image for Checkbox checked/unchecked event.

inside my login xml i have write :

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="5dp" >

        <CheckBox
            android:id="@+id/chk_remember_me"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:button="@drawable/checkbox_uncheked"
            android:paddingLeft="5dp"
            android:text="Remember Me"
            android:textColor="#024d94"
            android:textSize="12dp" />
    </LinearLayout>

Here i have Used android:paddingLeft="5dp" for getting space between button and textview.

My Problem : i got two different views for 2.3 and 4.2

for Device that has xhdpi or below density or that has large screen i am getting below screen (this one is perfect as i want ):

enter image description here

for Device that has hdpi or below density or that has normal/small screen i am getting below screen :

enter image description here

Can anyone tellme where am i missing? or anything Wrong in my layout?

I want the same layout screen which i am getting for 4.2 device in normal/large screen devices.

Thanks in advance.

Bhavesh Patadiya
  • 25,740
  • 15
  • 81
  • 107

3 Answers3

7

It appears that Checkbox already uses padding by default internally and overriding it with paddingLeft causes these issues. You should remove that property from your XML.

If you still want to adjust the padding, you will have to do so programatically. See this answer: https://stackoverflow.com/a/4038195/832776

To only apply it to >4.2 you can use the following, though I would test on emulators to make sure this issue isn't merely a problem with just your devices.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Community
  • 1
  • 1
Oleg Vaskevich
  • 12,444
  • 6
  • 63
  • 80
  • Thnk you very much for your support. but by removing paddingLeft i am getting default space inside 2.3 which is very much more than i want. and for 4.2 i am not getting any space between button and text. so by removing paddingLeft do not make my problem solve. – Bhavesh Patadiya Jan 05 '13 at 06:07
  • @Bhavesh use 2 different layout, one for 2.3, and other one for 4.2 – chengbo Jan 05 '13 at 06:13
  • @chengbo: hehe!!..thnks but it is not the solution i want. there should be a way to work around for this issue. – Bhavesh Patadiya Jan 05 '13 at 06:15
  • @OlegVaskevich: Thnks. i tried it out your Suggestion with link http://stackoverflow.com/a/4038195/832776 but getting not perfectly solve my problem works perfectly in 4.2 but getting much more space between button and textview for 2.3 devices. – Bhavesh Patadiya Jan 05 '13 at 06:27
  • Honestly this sounds like a manufacturer customization that didn't work too well; after all, you'd expect that checkboxes should look fine by default. – Oleg Vaskevich Jan 05 '13 at 06:32
0

Give the fixed width to check box hopefully this can resolved your problem.

deepak Sharma
  • 1,641
  • 10
  • 23
0

Don't give padding, it comes by default with Checkbox.

pioneerBhawna
  • 578
  • 7
  • 15