Android 在约束条件下,页边距是如何工作的?

Android 在约束条件下,页边距是如何工作的?,android,android-layout,android-constraintlayout,Android,Android Layout,Android Constraintlayout,主布局.xml: <android.support.constraint.ConstraintLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <CollapsingTextView android:layout_width="wrap_content" android:layout_height="wrap_

主布局.xml

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <CollapsingTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="8dp"
        android:textSize="16sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

它看起来像边界,约束布局不考虑<强>任何< /强>水平边距,只水平地定位文本视图

<代码>
这是因为您将文本视图的宽度设置为
“wrap\u content”

要强制它适应约束,您需要使用宽度
“0dp”
。这在功能上等同于
“匹配约束”
,但目前未将其视为选项

<android.support.constraint.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="wrap_content">

    <CollapsingTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="8dp"
        android:textSize="16sp"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>