TouchWiz上的Android CheckBox额外填充

时间:2013-09-02 14:49:18

标签: android android-layout checkbox samsung-mobile

我有一个包含TextView和CheckBox的布局,这看起来像我预期的Galaxy Nexus(4.2.2):

Galaxy Nexus, default CheckBox style

然而,当在Galaxy S3和S2上观看时,我在CheckBox的顶部,右侧和底部得到一些奇怪的填充,这会弄乱整个子视图的水平对齐:

Galaxy S3, default CheckBox style

XML布局:

<?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>

如果我使用选择器作为自定义复选框资源(我最终会尝试这样做),那就更加明显了:

    <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

其他人有过这种经历吗?显然,引力=“中心”似乎对TouchWiz没有影响...


编辑10-SEP-2013 -

我入侵了修复

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());   
}

这不太理想,但它现在可以达到目的。

2 个答案:

答案 0 :(得分:0)

您可以执行此操作(复选框将显示在左侧,文本将填充10dip到右侧),而不是使用单独的CheckBox和TextView:

<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"/>

诀窍是将android:drawableLeft的颜色设置为透明,并为android:drawablePadding指定一个值。此外,透明度允许您在任何背景颜色上使用此技术,而没有副作用 - 如颜色不匹配。

或者

您可以查看this

答案 1 :(得分:0)

与星系s2有同样的问题。在带有结果的三星远程测试实验室进行测试,Android版本也是相关的。似乎三星已将其修复为较新的版本。

    if (Build.MANUFACTURER.equals("samsung") && Build.MODEL.startsWith("GT-") && Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)