【问题标题】:How can I set a "layout_marginLeft(/Right)" from Constraint Layout Editor?如何从约束布局编辑器设置“layout_marginLeft(/Right)”?
【发布时间】:2017-12-26 05:23:05
【问题描述】:

我有一个 minSdk=15 的应用。

我正在尝试迁移到 ConstraintLayout。

几乎没问题。但是当我从 layout editor 更改 margin_left 的值时,layout_marginLeft/Right 属性被删除。

之前

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="24dp" 
        android:layout_marginStart="24dp" // <- I will set to 16dp from layout editor
    />

之后

<TextView
    android:layout_width="0dp"
    android:layout_height="wrap_content"
                                      // <- layout_marginLeft is removed...
    android:layout_marginStart="16dp" // <- it is ok
    />

预期行为

如果我从布局编辑器更改 marginLeft,

layout_marginLeft/Rightlayout_marginStart/End 已更改。

更新

我从下面设置值

成功改变layout_margineStart/End,但是layout_marginLeft/Right被移除了。

值被拒绝,layout_marginLeft/Right 被移除。

【问题讨论】:

    标签: android android-layout android-studio android-layout-editor


    【解决方案1】:

    我不知道你是如何改变它的,但就我而言,它没有发生。

    第二件事是你为什么要设置左右。你应该使用 start 和 end。

    您仍然想设置左右边距,您可以通过单击“查看所有属性”从属性选项卡中进行设置。


    你可以像下面这样添加它

    o

    点击工具(指定设计属性)按钮后即可添加。

    就像我为左边距做的那样。

    一个缓存是它仅用于设计角度。它将添加您需要的工具:layout_margineLeft 而不是 android:layout_margineLeft

    【讨论】:

    • 在 api 级别 16 中,不支持 layout_margin_start/end。所以我想设置 layout_marginLeft/Right。和*layout_marginLeft/Right 在布局编辑器的“查看所有属性”中,总是拒绝我的设置值。
    • 在我的 api 级别 16 模拟器中,它被忽略了 android:layout_marginStart/End 属性。在真机上能用吗?
    • 我需要 android:layout_marginLeft/Right。不是 tools:layout_marginLeft/Right.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-14
    • 2014-03-24
    相关资源
    最近更新 更多