在Android版的TouchWiz复选框微胖 [英] Android CheckBox extra padding on TouchWiz
问题描述
我有一个包含一个TextView和一个CheckBox一个布局,这看起来如预期在我的Galaxy Nexus(4.2.2):
I have a layout which contains a TextView and a CheckBox, and this looks as expected on my Galaxy Nexus (4.2.2):
在银河S3和S2观看时不过,我得到一些奇怪的填充顶端,右侧和被搞乱了整个子视图的水平对齐方式的CheckBox的底部:
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:
中的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>
如果我用了一个选择自定义复选框资源(这我最终想要做)这是更加明显:
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" />
银河S3:
Galaxy Nexus的:
任何人都经历过这样?显然,比重=中心似乎对的TouchWiz没有影响...
Anyone else experienced this? Obviously the gravity="center" appears to have no effect on 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());
}
这是不理想的,但它符合其目的了。
This is less than ideal but it serves its purpose for now.
推荐答案
,你可以这样做(的复选框会出现在左侧,文本将被填充10dip到右):
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"/>
关键是要设置颜色为透明的,的android:drawableLeft
并分配 Android的一个值:drawablePadding
。此外,透明度允许你使用任何背景颜色这种技术没有副作用 - 般的颜色不匹配
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.
或者
您可以检查这的出来。
这篇关于在Android版的TouchWiz复选框微胖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!