复选框文本显示在框顶部

时间:2013-11-12 22:58:23

标签: android layout checkbox android-4.2-jelly-bean overlapping

以下XML显示了一系列用于选择语言的复选框。它在JB 4.2中看起来很好,但是JB 4.1上的相同布局在复选框的顶部有文本。像这样:

enter image description here

我根据标准没做什么?

代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">


    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Language Setup"
            android:id="@+id/textView1"
            android:layout_gravity="center"
            android:textSize="30dp"
            android:paddingBottom="10dp"/>
    <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Please select the languages you would like :"
            android:id="@+id/textView"
            android:layout_marginLeft="10dp"/>

    <CheckBox android:id="@+id/chkInstallArabic"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Arabic"
              android:checked="true"
              android:enabled="false"
              android:paddingLeft="10dp"
              android:layout_marginLeft="10dp"/>

    <CheckBox android:id="@+id/chkInstallEnglish"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="English"
              android:checked="false"
              android:paddingLeft="10dp"
              android:layout_marginLeft="10dp"/>

    <CheckBox android:id="@+id/chkInstallUrdu"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Urdu"
              android:checked="false"
              android:paddingLeft="10dp"
              android:layout_marginLeft="10dp"/>

    <CheckBox android:id="@+id/chkInstallIndonesian"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Indonesian"
              android:checked="false"
              android:paddingLeft="10dp"
              android:layout_marginLeft="10dp"/>

    <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="I am happy!"
            android:id="@+id/btnInstall"
            android:onClick="onRunButtonClicked"
            />
</LinearLayout>

3 个答案:

答案 0 :(得分:2)

引用Android - Spacing between CheckBox and text,问题似乎是Android的CheckBox控件已经使用android:paddingLeft属性来获取文本所在的位置。如果你覆盖它,它可能会弄乱布局。因此,如果您删除android:paddingLeft="10dp"android:layout_marginLeft="10dp",它应该可以解决问题。

答案 1 :(得分:1)

在复选框中增加左边的填充

<CheckBox
    android:id="@+id/chkInstallArabic"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:checked="true"
    android:paddingLeft="40dp"
    android:text="Arabic" />

答案 2 :(得分:0)

将以下值添加到复选框中解决了我的问题

android:gravity="center"
相关问题