下面是一篇讨论ConstraintLayout
中负边距的博客文章。
使用空格表示负边距
ConstraintLayout中得视图不能具有负边距(不支持)。然而,通过一个简单的技巧,您可以通过插入一个空格(本质上是一个空视图)并将其大小设置为您想要的边距来实现类似的功能。
android:translationX="-10dp"
android:translationY="-10dp"
您可以使用一个视图来保存一个固定值,如30DP,如下所示:
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="45dp"
app:layout_constraintBottom_toBottomOf="@id/space"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:mapbox_uiRotateGestures="false" />
<View
android:id="@+id/space"
android:layout_width="match_parent"
android:layout_height="30dp"
app:layout_constraintTop_toBottomOf="parent" />