Android:如何使ImageButton在GridLayout中具有相同的空间?
嘿,我需要做这个: 在图像之间的间距更相等。我的意思是在所有轴上的4个图像之间有相同的空间,如下所示: 注意:这里使用的Kenny图像仅用于虚拟图像源 这是我的xml文件:Android:如何使ImageButton在GridLayout中具有相同的空间?,android,xml,android-studio,android-layout,Android,Xml,Android Studio,Android Layout,嘿,我需要做这个: 在图像之间的间距更相等。我的意思是在所有轴上的4个图像之间有相同的空间,如下所示: 注意:这里使用的Kenny图像仅用于虚拟图像源 这是我的xml文件: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android
<?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=".MainActivity">
<androidx.gridlayout.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:columnCount="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:rowCount="2">
<ImageButton
android:id="@+id/imageButton"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@null"
android:scaleType="fitCenter"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
app:srcCompat="@drawable/kenny" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@null"
android:scaleType="fitCenter"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
app:srcCompat="@drawable/kenny" />
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@null"
android:scaleType="fitCenter"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
app:srcCompat="@drawable/kenny" />
<ImageButton
android:id="@+id/imageButton4"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@null"
android:scaleType="fitCenter"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
app:srcCompat="@drawable/kenny" />
</androidx.gridlayout.widget.GridLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
我找了很多,但找不到一个方法来做我想要的。感谢添加应用程序:使用DefaultMargins=“true”,并尝试为项目提供边距。android:scaleType=“fitXY”如何?不,这让它变得很有弹性。我想保存图像的纵横比图像将以正方形显示?是的,我想我的图像以正方形显示,每个按钮之间的间距相同。谢谢你的帮助,但我想使每个按钮的左右间距与顶部和底部相同。希望有意义。你能试着提供保证金吗?