使用约束布局的均匀间隔(全高)菜单

时间:2017-12-01 21:35:06

标签: android android-layout

我搜索了Android网站,但在我的生活中,我似乎无法弄清楚如何获得没有空格的全屏菜单。我已经检查了边距,填充等。我也使用了百分比作为指导,但我的按钮之间仍然有间距。有人可以帮忙吗?我的所有按钮也设置为零分贝。

    <?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:layout_editor_absoluteY="25dp"
    tools:layout_editor_absoluteX="0dp">



    <Button
        android:id="@+id/button5"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:backgroundTint="#66bb6a"
        android:elevation="0dp"
        android:onClick="startFlashcardA"
        android:text="  Flashcards"
        android:textAlignment="viewStart"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/guideline22"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0"/>

    <Button
        android:id="@+id/button"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:backgroundTint="@android:color/holo_purple"
        android:elevation="0dp"
        android:onClick="startVideoA"
        android:padding="0dp"
        android:text="  Videos"
        android:textAlignment="viewStart"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/guideline27"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@id/guideline22"
        app:layout_constraintVertical_bias="0.0"
        />

    <Button
        android:id="@+id/button6"
        android:layout_width="0dp"
        android:layout_height="125dp"
        android:backgroundTint="#f06292"
        android:onClick="startSoundsMenu"
        android:text="  Letter Sounds"
        android:textAlignment="viewStart"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/guideline28"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline27"
        app:layout_constraintVertical_bias="0.0"/>

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:backgroundTint="@android:color/holo_blue_dark"
        android:text="  About Mr. Pea"
        android:textAlignment="viewStart"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="@+id/guideline29"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline28"
        app:layout_constraintVertical_bias="0.0"/>

    <android.support.constraint.Guideline
        android:id="@+id/guideline22"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.2"
        tools:layout_editor_absoluteY="114dp"
        tools:layout_editor_absoluteX="0dp"/>

    <android.support.constraint.Guideline
        android:id="@+id/guideline27"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.4"
        tools:layout_editor_absoluteY="227dp"
        tools:layout_editor_absoluteX="0dp"/>

    <android.support.constraint.Guideline
        android:id="@+id/guideline28"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.6"
        tools:layout_editor_absoluteY="340dp"
        tools:layout_editor_absoluteX="0dp"/>

    <android.support.constraint.Guideline
        android:id="@+id/guideline29"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.8"
        tools:layout_editor_absoluteY="454dp"
        tools:layout_editor_absoluteX="0dp"/>

    <Button
        android:id="@+id/button4"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:backgroundTint="#887c5a"
        android:text="  Contributions"
        android:textAlignment="viewStart"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/guideline29"
        app:layout_constraintVertical_bias="0.0"/>

</android.support.constraint.ConstraintLayout>

1 个答案:

答案 0 :(得分:0)

无需指导。只需在两个方向上建立一个良好连接的链条。您可能需要更正button的填充。

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="25dp">

    <Button
        android:id="@+id/button5"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:backgroundTint="#66bb6a"
        android:elevation="0dp"
        android:onClick="startFlashcardA"
        android:text="  Flashcards"
        android:textAlignment="viewStart"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/button"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />

    <Button
        android:id="@+id/button"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:backgroundTint="@android:color/holo_purple"
        android:elevation="0dp"
        android:onClick="startVideoA"
        android:padding="0dp"
        android:text="  Videos"
        android:textAlignment="viewStart"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/button6"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/button5"
        app:layout_constraintVertical_bias="0.0" />

    <Button
        android:id="@+id/button6"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:backgroundTint="#f06292"
        android:onClick="startSoundsMenu"
        android:text="  Letter Sounds"
        android:textAlignment="viewStart"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/button2"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button"
        app:layout_constraintVertical_bias="0.0" />

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:backgroundTint="@android:color/holo_blue_dark"
        android:text="  About Mr. Pea"
        android:textAlignment="viewStart"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/button4"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button6"
        app:layout_constraintVertical_bias="0.0" />

    <Button
        android:id="@+id/button4"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:backgroundTint="#887c5a"
        android:text="  Contributions"
        android:textAlignment="viewStart"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button2"
        app:layout_constraintVertical_bias="0.0" />

</android.support.constraint.ConstraintLayout>

enter image description here