约束布局中的不同边距

时间:2018-08-03 11:57:20

标签: android-constraintlayout

我使用Android的约束布局创建了一个启动板。我为启动板添加了按钮,并使用链功能将一些按钮排列成行和列。

正如您在图片中所看到的,行之间的空间(标有红色)大于列之间的空间(标有蓝色)现在相等,这是我一个人无法解决的问题。 如何获得相同的空间?

Buttons in constrainslayout

这是我的按钮定义:

<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/taalsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:orientation="vertical"
tools:layout_editor_absoluteY="81dp">

<com.mapani.launchpad.XButton
    android:id="@+id/geda"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:elevation="0dp"
    android:fontFamily="monospace"
    android:text="@string/geda"
    android:textAllCaps="false"
    android:textSize="15sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toTopOf="@+id/mogholi"
    app:layout_constraintEnd_toStartOf="@+id/kehrwa"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<com.mapani.launchpad.XButton
    android:id="@+id/kehrwa"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:fontFamily="monospace"
    android:text="@string/kehrwa"
    android:textAllCaps="false"
    android:textSize="15sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toTopOf="@+id/rupak"
    app:layout_constraintEnd_toStartOf="@+id/dadra"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toEndOf="@+id/geda"
    app:layout_constraintTop_toTopOf="@+id/geda" />

<com.mapani.launchpad.XButton
    android:id="@+id/dadra"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:fontFamily="monospace"
    android:text="@string/dadra"
    android:textAllCaps="false"
    android:textSize="15sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toTopOf="@+id/tapea"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toEndOf="@+id/kehrwa"
    app:layout_constraintTop_toTopOf="@+id/kehrwa" />

<com.mapani.launchpad.XButton
    android:id="@+id/mogholi"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:fontFamily="monospace"
    android:text="@string/mogholi"
    android:textAllCaps="false"
    android:textSize="15sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toTopOf="@+id/sitarkhani"
    app:layout_constraintEnd_toStartOf="@+id/rupak"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/geda" />

<com.mapani.launchpad.XButton
    android:id="@+id/rupak"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:fontFamily="monospace"
    android:text="@string/rupak"
    android:textAllCaps="false"
    android:textSize="15sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toTopOf="@+id/japtaal"
    app:layout_constraintEnd_toStartOf="@+id/tapea"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toEndOf="@+id/mogholi"
    app:layout_constraintTop_toTopOf="@+id/mogholi" />

<com.mapani.launchpad.XButton
    android:id="@+id/tapea"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:fontFamily="monospace"
    android:text="@string/tapea"
    android:textAllCaps="false"
    android:textSize="15sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toTopOf="@+id/teentaal"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toEndOf="@+id/rupak"
    app:layout_constraintTop_toTopOf="@+id/rupak" />

<com.mapani.launchpad.XButton
    android:id="@+id/sitarkhani"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:fontFamily="monospace"
    android:text="@string/sitarkhani"
    android:textAllCaps="false"
    android:textSize="15sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toTopOf="@+id/ektaal"
    app:layout_constraintEnd_toStartOf="@+id/japtaal"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/mogholi" />

<com.mapani.launchpad.XButton
    android:id="@+id/japtaal"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:fontFamily="monospace"
    android:text="@string/japtaal"
    android:textAllCaps="false"
    android:textSize="15sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toTopOf="@+id/C"
    app:layout_constraintEnd_toStartOf="@+id/teentaal"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toEndOf="@+id/sitarkhani"
    app:layout_constraintTop_toTopOf="@+id/sitarkhani" />

<com.mapani.launchpad.XButton
    android:id="@+id/teentaal"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:fontFamily="monospace"
    android:text="@string/teentaal"
    android:textAllCaps="false"
    android:textSize="15sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toTopOf="@+id/D"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toEndOf="@+id/japtaal"
    app:layout_constraintTop_toTopOf="@+id/japtaal" />

<com.mapani.launchpad.XButton
    android:id="@+id/ektaal"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:fontFamily="monospace"
    android:text="@string/ektaal"
    android:textAllCaps="false"
    android:textSize="15sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toStartOf="@+id/C"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/sitarkhani" />

<com.mapani.launchpad.XButton
    android:id="@+id/C"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:text="سا"
    android:textAllCaps="false"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toStartOf="@+id/D"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toEndOf="@+id/ektaal"
    app:layout_constraintTop_toTopOf="@+id/ektaal" />

<com.mapani.launchpad.XButton
    android:id="@+id/D"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:text="Button"
    android:textAllCaps="false"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toEndOf="@+id/C"
    app:layout_constraintTop_toTopOf="@+id/C" />
</android.support.constraint.ConstraintLayout>

1 个答案:

答案 0 :(得分:1)

这是因为行和列的大小在布局的高度和宽度上有所不同。减小按钮的宽度将允许U使列的高度相等。