【问题标题】:Why don't work Gravity center for Check Box为什么不为复选框工作重力中心
【发布时间】:2020-10-12 10:15:27
【问题描述】:

我有一个复选框并设置了重心,但该框没有居中

这是我的 XML 文件

<CheckBox
    android:id="@+id/checkBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="32dp"
    android:layout_marginTop="8dp"
    android:gravity="center"
    android:checked="false"
    android:clickable="false"
    app:buttonTint="@color/colorPrimary"
    android:scaleX="1.4"
    android:scaleY="1.4"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

复选框图片:

【问题讨论】:

  • 使用什么类型的布局?
  • @liangZhenbo 我使用了约束布局
  • 你找到答案了吗?

标签: android xml android-studio android-layout checkbox


【解决方案1】:

约束布局链 Android 开发人员最近发布了新版本的 ConstraintLayout(截至今天为 1.0.2)。此版本包含一个新的主要功能 - 链,它允许我们在 ConstraintLayout 中对视图进行分组。

链在单轴(水平或垂直)上提供类似组的行为。

如果一组小部件通过双向连接链接在一起,则它们被视为一个链

一旦创建了一条链,就有两种可能:

在可用空间中散布元素 链也可以“打包”,在这种情况下,元素被组合在一起

【讨论】:

    【解决方案2】:

    也许我弄错了,但我对单选按钮进行了同样的尝试,它只将与单选按钮关联的文本居中。但我想你可能会在这里找到答案:https://stackoverflow.com/questions/47386980/align-checkbox-to-center-of-the-listview-item/47387075#:~:text=Create%20a%20LinearLayout%20as%20PARENT.&text=If%20you%20check%20the%20device,It%20should%20work

    【讨论】:

    • 你有一个约束布局。在里面你需要做一个线性布局,你将在其中放置复选框。
    【解决方案3】:

    我自己用样式解决了这个问题

    先设置样式属性

    android:theme="@style/checkBoxStyle"
    

    创建样式

    <style name="checkBoxStyle" parent="Base.Theme.AppCompat">
        <item name="colorAccent">@color/colorPrimary</item>
        <item name="android:textColorSecondary">@color/colorPrimary</item>
    </style>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-11
      • 1970-01-01
      • 1970-01-01
      • 2019-06-25
      相关资源
      最近更新 更多