0

On Android 4.4 KitKat, my two apps has the problem. But on the other Android platform under 4.4 like 4.0 and 2.3.3, they display well.

The device I use is LG Nexus 5.

Here are two examples:

CheckBox:

<LinearLayout
        android:id="@+id/CheckBoxGroup"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:orientation="vertical" >

        <CheckBox
            android:id="@+id/CheckBoxRememberMe"
            style="@style/FontSmallBald"
            android:layout_width="150dp"
            android:layout_height="50dp"
            android:button="@drawable/checkbox_remember_image_state"
            android:checked="true"
            android:gravity="center_vertical"
            android:text="@string/remember_me" >

        </CheckBox>

        <CheckBox
            android:id="@+id/CheckBoxKeepMeLogin"
            style="@style/FontSmallBald"
            android:layout_width="150dp"
            android:layout_height="50dp"
            android:button="@drawable/checkbox_remember_image_state"
            android:checked="false"
            android:gravity="center_vertical"
            android:text="@string/keep_me_login" />

    </LinearLayout>
<style name="FontSmallBald">
    <item name="android:textSize">12sp</item>
    <item name="android:textStyle">bold</item>
</style>

The CheckBox is displayed like this : BOX * no space * keep me login .

But on 4.0 or 2.3.3 it is displayed like this: BOX * default DP space * keep me login .

Button:

    button.setGravity(Gravity.CENTER_VERTICAL);
    button.setPadding(85,0,0,0);

Althouth I set 85dp paddingLeft but it results in different appearence. On Android 4.4 the text is much more closer(not algin at and it seems that 85dp is shrinked to 50dp) to the left edge of the button but does not on the other.

Anyone knows why on Android 4.4 the rendering is different compared with other version of Android and how to set the attribute to make them look the same?

user3089953
  • 1
  • 1
  • 4

1 Answers1

0

setPadding() set padding in pixels, not dp.

You can use screen width/x for padding to get a same result.

SEE:

setPadding: http://developer.android.com/reference/android/view/View.html#setPadding(int, int, int, int)

how to get device screen size

Community
  • 1
  • 1
mht
  • 80
  • 2
  • 7