【问题标题】:Android CheckBox extra padding on TouchWizTouchWiz 上的 Android CheckBox 额外填充
【发布时间】:2013-09-05 17:20:15
【问题描述】:

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

但是,在 Galaxy S3 和 S2 上查看时,我在 CheckBox 的顶部、右侧和底部得到了一些奇怪的填充,这弄乱了整个子视图的水平对齐:

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

银河 S3:

银河系:

其他人经历过这种情况吗?显然,gravity="center" 似乎对 TouchWiz 没有影响...


编辑 2013 年 9 月 10 日 -

我破解了一个补丁

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

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

【问题讨论】:

    标签: android android-layout checkbox samsung-mobile


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      您可以这样做,而不是使用单独的 CheckBox 和 TextView(复选框将出现在左侧,文本将向右填充 10dip):

      <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

      【讨论】:

      • 我不太确定这会有什么帮助 - 可绘制对象位于复选框本身的文本左侧/右侧,如果有的话,这会增加两者之间的距离。 CheckedTextView 很有趣,感谢您的链接,我以前没有发现过。但是,我的设计要求文本位于复选框的左侧。
      • @warbi:没问题。 CheckedTextView 将是您想要的。 :)
      • 对不起,我的意思是它很有趣,但它不适合,因为我的复选框需要位于文本的右侧 - CheckedTextView 基本上会给我与复选框相同的功能,但给我不必有一个实际的“盒子”的选项,是吗? :-/
      • 是和不是。我没有要在此处发布的 CheckedTextView 的屏幕转储,但也许 link 可以为您提供一些关于在您的应用中使用 CheckedTextView 组件的想法。
      猜你喜欢
      • 2013-11-20
      • 2016-07-24
      • 1970-01-01
      • 1970-01-01
      • 2018-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-16
      相关资源
      最近更新 更多