【问题标题】:Android Constraint Layout margins change then revert backAndroid 约束布局边距更改然后恢复
【发布时间】:2020-05-08 04:26:46
【问题描述】:

设置所有四个布局约束后,我尝试设置边距。边距变形为所需的 UI(照片 #2),但随后立即恢复为原始形式(照片 #1)。这有效地消除了对边距设置的更改。照片#3 是一个更明显的问题示例。有谁知道怎么回事?

1

UI before and after adding margin (there is no change)

2

desired UI (effect the margin should have)

3

strange UI result (separate from 1 & 2, is an example of the problem)

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
tools:context=".SettingsActivity">

<TextView
    android:id="@+id/settingsTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Settings"
    android:textColor="@android:color/white"
    android:textSize="36sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Spinner
    android:id="@+id/turnSettingSpinner"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginTop="100dp"
    android:background="@android:color/white"
    android:entries="@array/turn_settings"
    android:spinnerMode="dropdown"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/settingsTextView" />

</androidx.constraintlayout.widget.ConstraintLayout>

【问题讨论】:

  • 显示你想要的预期用户界面吗?
  • 照片 #2 是所需的 UI,照片 #1 是结果,与边距限制无关

标签: android android-constraintlayout layoutmargins


【解决方案1】:

layout_margin 设置为 8dp,因此我对四个指定边距(即 layout_marginTop、layout_marginLeft 等)所做的每一次更改都不会“粘住”,而是恢复为指定的默认值 8dp。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-05
    • 2018-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多