我的项目使用的是 Constraintlayout 1.1.3,我刚刚将其版本更新为 2.0.4。
整个布局的一部分有点混乱。所以我检查了我的代码,我意识到我使用 layout_ConstraintLeft 或 right。
所以我添加了ConstraintLayout属性的“开始”和“结束”。但它仍然无法正常工作。
他们互相粘着。
此约束布局由平面层次结构组成。这个布局的另一部分仍然有效。
为什么它不起作用?
我该如何解决?
但它最终就像 tihs 一样。他们互相粘着。当我升级 ConstraintLayout 版本时。
这是我的 xml 代码。
<?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:custom="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="#FFF"
android:fillViewport="true"
android:clickable="true"
tools:context=".ManiActivity">
<ImageView
android:id="@+id/container_outline"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#333"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHeight_percent="0.25"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0"
tools:viewBindingIgnore="true" />
<ImageView
android:id="@+id/iv_drawer_info_logo"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:src="@drawable/img_drawer_logo"
app:layout_constraintBottom_toBottomOf="@id/container_outline"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintHeight_percent="0.15"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintLeft_toLeftOf="@id/container_outline"
app:layout_constraintStart_toStartOf="@id/container_outline"
app:layout_constraintRight_toRightOf="@id/container_outline"
app:layout_constraintEnd_toEndOf="@id/container_outline"
app:layout_constraintTop_toTopOf="@id/container_outline"
tools:viewBindingIgnore="true" />
<ImageView
android:id="@+id/iv_drawer_info_name_icon"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginLeft="10dp"
android:paddingTop="1dp"
android:src="@drawable/icn_drawer_name"
app:layout_constraintBottom_toBottomOf="@id/tv_drawer_info_name"
app:layout_constraintDimensionRatio="3:5"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintLeft_toRightOf="@id/iv_drawer_info_logo"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/tv_drawer_info_name"
app:layout_constraintVertical_bias="1"
tools:viewBindingIgnore="true" />
<TextView
android:id="@+id/tv_drawer_info_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:gravity="left|bottom"
android:textColor="#FFF"
android:textSize="@dimen/text_main_big"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@id/tv_drawer_info_id"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintLeft_toRightOf="@id/iv_drawer_info_name_icon"
app:layout_constraintRight_toRightOf="@id/container_outline"
app:layout_constraintTop_toTopOf="@id/container_outline"
app:layout_constraintVertical_chainStyle="packed"
tools:text="Hello" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_drawer_info_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/detail_margin_3"
android:ellipsize="end"
android:maxLines="1"
android:textColor="#FFF"
android:textSize="14dp"
app:autoSizeMaxTextSize="14dp"
app:autoSizeMinTextSize="9dp"
app:autoSizeTextType="uniform"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="@id/container_outline"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintLeft_toLeftOf="@id/iv_drawer_info_name_icon"
app:layout_constraintStart_toStartOf="@id/iv_drawer_info_name_icon"
app:layout_constraintRight_toLeftOf="@id/iv_drawer_info_expire_icon"
app:layout_constraintEnd_toStartOf="@id/iv_drawer_info_expire_icon"
app:layout_constraintTop_toBottomOf="@id/tv_drawer_info_name"
tools:text="hello wordhello wordhello wordhello wordhello wordhello wordhello wordhello word" />
<ImageView
android:id="@+id/iv_drawer_info_expire_icon"
android:layout_width="20dp"
android:layout_height="0dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginRight="3dp"
android:layout_marginEnd="3dp"
android:paddingTop="1dp"
android:src="@drawable/icn_drawer_expire"
app:layout_constraintBottom_toBottomOf="@id/tv_drawer_info_expire_title"
app:layout_constraintHorizontal_bias="1"
app:layout_constraintLeft_toLeftOf="@id/container_outline"
app:layout_constraintStart_toStartOf="@id/container_outline"
app:layout_constraintRight_toLeftOf="@id/tv_drawer_info_expire_title"
app:layout_constraintEnd_toStartOf="@id/tv_drawer_info_expire_title"
app:layout_constraintTop_toTopOf="@id/tv_drawer_info_expire_title"
app:layout_constraintVertical_bias="1"
tools:viewBindingIgnore="true" />
<TextView
android:id="@+id/tv_drawer_info_expire_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left|bottom"
android:text="Hello word"
android:textColor="#FFF"
android:textSize="14dp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@id/tv_drawer_info_expire"
app:layout_constraintHorizontal_bias="0.6"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/container_outline"
app:layout_constraintVertical_chainStyle="packed"
tools:viewBindingIgnore="true" />
<TextView
android:id="@+id/tv_drawer_info_expire"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/detail_margin_3"
android:textColor="#FFF"
android:textSize="14dp"
app:layout_constraintBottom_toBottomOf="@id/container_outline"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintLeft_toLeftOf="@id/iv_drawer_info_expire_icon"
app:layout_constraintStart_toStartOf="@id/iv_drawer_info_expire_icon"
app:layout_constraintRight_toRightOf="@id/container_outline"
app:layout_constraintEnd_toEndOf="@id/container_outline"
app:layout_constraintTop_toBottomOf="@id/tv_drawer_info_expire_title"
tools:text="~2020.12.31" />
<ImageButton
android:id="@+id/btn_drawer_pay"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginRight="24dp"
android:background="@drawable/ripple_white"
android:padding="15dp"
android:scaleType="fitCenter"
android:src="@drawable/img_drawer_payment"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="@id/iv_drawer_info_logo"
app:layout_constraintDimensionRatio="4:3"
app:layout_constraintHeight_percent="0.15"
app:layout_constraintHorizontal_bias="1"
app:layout_constraintLeft_toLeftOf="@id/container_outline"
app:layout_constraintStart_toStartOf="@id/container_outline"
app:layout_constraintRight_toRightOf="@id/container_outline"
app:layout_constraintEnd_toEndOf="@id/container_outline"
app:layout_constraintTop_toTopOf="@id/iv_drawer_info_logo" />
</androidx.constraintlayout.widget.ConstraintLayout>