【发布时间】:2017-12-03 22:02:09
【问题描述】:
我的布局中有四个按钮的网格。我将它们水平链接起来,以便左右按钮之间的空间均匀加权。
screenshot of my app's buttons
我是否可以让两排按钮在它们之间具有相同的垂直间距,这样看起来才不会不均匀?我宁愿不只是像我为实现水平间距所做的那样将它们垂直居中,这要感谢这篇文章的@AdamK:Evenly spacing views using ConstraintLayout
activity_main.xml:
<android.support.constraint.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="com.jason.notifier.MainActivity" tools:layout_editor_absoluteY="81dp" tools:layout_editor_absoluteX="0dp"> <ImageView android:id="@+id/imageView3" android:layout_width="388dp" android:layout_height="164dp" app:srcCompat="@drawable/banner" android:layout_marginStart="8dp" app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="4dp" android:layout_marginLeft="8dp" app:layout_constraintLeft_toLeftOf="parent" /> <Button android:id="@+id/testbutton" android:layout_width="171dp" android:layout_height="136dp" android:onClick="sampleNotification" android:text="Test" app:layout_constraintRight_toLeftOf="@+id/settingsbutton" app:layout_constraintLeft_toLeftOf="parent" android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/historybutton" /> <Button android:id="@+id/settingsbutton" android:layout_width="171dp" android:layout_height="136dp" android:text="Settings" android:onClick="settingsbutton" app:layout_constraintRight_toRightOf="parent" app:layout_constraintLeft_toRightOf="@+id/testbutton" android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/pingbutton" /> <Button android:id="@+id/pingbutton" android:layout_width="171dp" android:layout_height="136dp" android:onClick="pingbutton" android:text="ping" android:layout_marginTop="-31dp" app:layout_constraintTop_toBottomOf="@+id/textView2" app:layout_constraintRight_toRightOf="parent" app:layout_constraintLeft_toRightOf="@+id/historybutton" /> <Button android:id="@+id/historybutton" android:layout_width="171dp" android:layout_height="136dp" android:onClick="historybutton" android:text="History" android:layout_marginTop="-31dp" app:layout_constraintTop_toBottomOf="@+id/textView2" app:layout_constraintRight_toLeftOf="@+id/pingbutton" app:layout_constraintLeft_toLeftOf="parent" /> <TextView android:id="@+id/textView2" android:layout_width="358dp" android:layout_height="42dp" android:text="TextView" android:gravity="center" tools:layout_editor_absoluteX="2dp" android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/imageView3" /> </android.support.constraint.ConstraintLayout>
【问题讨论】:
-
分享你的约束布局 XML
标签: android android-constraintlayout android-studio-2.3