水平方向需要设置步骤如下
设置view的layoutwidth=0dp,id分别为view1,view2分别view1 view2的 app:layout_constraintHorizontal_weight="1" 分别设置view1与view2的左右依赖与上面类似,不需要需要设置的属性如下:
layout_constraintVertical_weight="xxx",另外需要设置垂直方向的约束,尤其是<?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" tools:context=".activity.maintain.MapMaintainLocationActivity"> <com.amap.api.maps.TextureMapView android:id="@+id/map_view" android:layout_width="match_parent" android:layout_height="0dp" app:layout_constraintBottom_toTopOf="@+id/constrain_bottom" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_weight="3" /> <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/constrain_bottom" android:layout_width="match_parent" android:layout_height="0dp" android:background="@drawable/bg_top_cornel" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toBottomOf="@+id/map_view" app:layout_constraintVertical_weight="2"> <Button style="@style/button_round" android:layout_marginBottom="20dp" android:text="确定" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>