Android约束布局边距先更改然后返回

问题描述 投票:0回答:1

设置所有四个布局约束后,我尝试设置边距。边距变形为所需的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>
android android-constraintlayout layoutmargins
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.