【问题标题】:Checkbox text displays on top of box复选框文本显示在框的顶部
【发布时间】:2013-11-25 08:11:43
【问题描述】:

以下 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>

【问题讨论】:

  • 可以贴一下外部布局规范吗?
  • 对不起,我已经这样做了,所以由于某种原因没有拿起它,现在重新格式化你可以看到它。
  • &lt;CheckBox android:id="@+id/chkInstallArabic" 中删除android:paddingLeft="10dp"android:layout_marginLeft="10dp" 会发生什么?
  • @ShobhitPuri 已修复!但我不知道为什么......
  • 主要是因为你覆盖了 padding 属性。阅读:stackoverflow.com/questions/4037795/…。它将帮助您了解原因:)

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


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    增加复选框左侧的填充

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

    【讨论】:

    • 是的,我可以添加内边距,但这似乎有点小技巧,它会影响我在手机上的布局吗?
    • 如果你担心多分辨率屏幕,没有问题,因为40 dp不会影响你布局的主要组织
    【解决方案3】:

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

    android:gravity="center"
    

    【讨论】:

      猜你喜欢
      • 2016-05-31
      • 1970-01-01
      • 2017-06-20
      • 2012-10-07
      • 1970-01-01
      • 1970-01-01
      • 2013-11-02
      • 2013-09-14
      • 2011-11-13
      相关资源
      最近更新 更多