我用
约束布局
在我的Android项目中,我在UI中放置了四个图像按钮,我希望四个图像按钮之间的距离相等,似乎两者都一样
布局A
和
布局B
图像AB
两者有什么不同
?
布局A
<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:id="@+id/camera_ui_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="@+id/btnFlash"
android:layout_width="@dimen/round_button_medium"
android:layout_height="@dimen/round_button_medium"
android:layout_marginLeft="@dimen/margin_xsmall"
android:layout_marginBottom="@dimen/margin_medium"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/btnVideo"
app:srcCompat="@drawable/ic_flash_on" />
<ImageButton
android:id="@+id/btnVideo"
android:layout_width="@dimen/round_button_medium"
android:layout_height="@dimen/round_button_medium"
android:layout_marginBottom="@dimen/margin_medium"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/btnFlash"
app:layout_constraintRight_toLeftOf="@+id/btnPicture"
app:srcCompat="@drawable/ic_menu" />
<ImageButton
android:id="@+id/btnPicture"
android:layout_width="@dimen/round_button_medium"
android:layout_height="@dimen/round_button_medium"
android:layout_marginBottom="@dimen/margin_medium"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/btnVideo"
app:layout_constraintRight_toLeftOf="@+id/btnAction"
app:srcCompat="@drawable/ic_menu" />
<ImageButton
android:id="@+id/btnAction"
android:layout_width="@dimen/round_button_medium"
android:layout_height="@dimen/round_button_medium"
android:layout_marginRight="@dimen/margin_xsmall"
android:layout_marginBottom="@dimen/margin_medium"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@+id/btnPicture"
app:srcCompat="@drawable/ic_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
布局B
<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:id="@+id/camera_ui_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="@+id/btnFlash"
android:layout_width="@dimen/round_button_medium"
android:layout_height="@dimen/round_button_medium"
android:layout_marginLeft="@dimen/margin_xsmall"
android:layout_marginBottom="@dimen/margin_medium"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintLeft_toLeftOf="parent"
app:srcCompat="@drawable/ic_flash_on" />
<ImageButton
android:id="@+id/btnVideo"
android:layout_width="@dimen/round_button_medium"
android:layout_height="@dimen/round_button_medium"
android:layout_marginBottom="@dimen/margin_medium"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/btnFlash"
app:layout_constraintRight_toLeftOf="@+id/btnPicture"
app:srcCompat="@drawable/ic_menu" />
<ImageButton
android:id="@+id/btnPicture"
android:layout_width="@dimen/round_button_medium"
android:layout_height="@dimen/round_button_medium"
android:layout_marginBottom="@dimen/margin_medium"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/btnVideo"
app:layout_constraintRight_toLeftOf="@+id/btnAction"
app:srcCompat="@drawable/ic_menu" />
<ImageButton
android:id="@+id/btnAction"
android:layout_width="@dimen/round_button_medium"
android:layout_height="@dimen/round_button_medium"
android:layout_marginRight="@dimen/margin_xsmall"
android:layout_marginBottom="@dimen/margin_medium"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:srcCompat="@drawable/ic_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
图像AB