ConstraintLayout 设置 margin 为负值的时候,并不能像其他布局,如相对布局那样使用(TMD)不知道为什么,用什么辅助实现?
Space 对,用这个
来,撸码
<layout 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">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layoutRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gg_room_bg">
<View
android:id="@+id/viewRoomVipUsers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="215dp"
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
<!-- 相对上面的控件 top 负25dp、 left 负 15dp -->
<Space
android:id="@+id/marginSpacer"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="25dp"
android:layout_marginStart="15dp"
app:layout_constraintBottom_toBottomOf="@+id/viewRoomVipUsers"
app:layout_constraintLeft_toLeftOf="@id/viewRoomVipUsers"
app:layout_constraintRight_toRightOf="@id/viewRoomVipUsers" />
<View
android:id="@+id/enterLevelRoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/marginSpacer"
android:visibility="gone"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
ok,可以了,去把自己的嵌套去掉吧!