【问题标题】:ConstraintLayout applying margin bottom to a view, also applies it to the top of the viewConstraintLayout 将边距底部应用于视图,也将其应用于视图的顶部
【发布时间】:2018-03-31 02:01:06
【问题描述】:
【问题讨论】:
标签:
java
android
android-layout
android-studio
android-constraintlayout
【解决方案1】:
根据我在您的附件中看到的内容,您正在创建一个垂直链,但您没有将“描述”限制在底部。这可能会导致问题,因为约束布局不知道链的结束位置。确保添加 app:layout_constraintBottom_toBottomOf="parent" 或任何您需要的视图作为描述 TextView 的底部链约束。
我重新创建了您的示例,并且编辑文本有镜像边距。
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
app:layout_constraintBottom_toTopOf="@id/editText"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="spread" />
<EditText
android:id="@+id/editText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="edit text"
app:layout_constraintBottom_toTopOf="@+id/description"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/name" />
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Description"
android:textColor="@color/colorTextPrimaryLight"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText" />
您可以尝试使用 chainStyle,看看哪种最适合您的需求。