以下 XML 显示了一系列用于选择语言的复选框。它在 JB 4.2 中看起来不错,但 JB 4.1 上的相同布局将文本放在复选框顶部。就像这样:
我有什么不符合标准的事情吗?
代码:
<?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>
最佳答案
引用Android - Spacing between CheckBox and text ,问题似乎是 Android 的 CheckBox 控件已经使用 android:paddingLeft
属性来获取文本所在的位置。如果您覆盖它,可能会弄乱布局。因此,如果您删除 android:paddingLeft="10dp"
和 android:layout_marginLeft="10dp"
,它应该可以解决问题。
关于android - 复选框文本显示在框顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19941705/