Android studio 4 Button on full screen [closed]

百般思念 提交于 2020-06-07 07:36:09

问题


I was beginner in android studio, Can anyone show me the way how to design 4 button cover all the screen

i want to design like this


回答1:


Try this using ConstraintLayout

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imgOne"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"
        app:layout_constraintBottom_toTopOf="@+id/imgThree"
        app:layout_constraintEnd_toStartOf="@id/imgTwo"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="NEW ITEM"
        android:textColor="@color/colorBlack"
        app:layout_constraintBottom_toBottomOf="@id/imgOne"
        app:layout_constraintEnd_toStartOf="@id/imgTwo"
        app:layout_constraintStart_toStartOf="parent" />

    <ImageView
        android:id="@+id/imgTwo"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@color/colorblue"
        app:layout_constraintBottom_toTopOf="@+id/imgFour"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@id/imgOne"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="NEW ITEM"
        android:textColor="@color/colorBlack"
        app:layout_constraintBottom_toBottomOf="@id/imgTwo"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="@id/imgTwo" />

    <ImageView
        android:id="@+id/imgThree"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@color/colorGreen"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@id/imgTwo"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imgOne" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="NEW ITEM"
        android:textColor="@color/colorBlack"
        app:layout_constraintBottom_toBottomOf="@id/imgThree"
        app:layout_constraintEnd_toStartOf="@id/imgFour"
        app:layout_constraintStart_toStartOf="parent" />

    <ImageView
        android:id="@+id/imgFour"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@color/colorAccent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@id/imgThree"
        app:layout_constraintTop_toBottomOf="@+id/imgTwo" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="NEW ITEM"
        android:textColor="@color/colorBlack"
        app:layout_constraintBottom_toBottomOf="@id/imgThree"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="@id/imgTwo" />

</androidx.constraintlayout.widget.ConstraintLayout>




回答2:


This is the easiest way to it.

LinearLayout :

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <androidx.appcompat.widget.LinearLayoutCompat
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <androidx.appcompat.widget.AppCompatImageButton
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" />

        <androidx.appcompat.widget.AppCompatImageButton
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" />
    </androidx.appcompat.widget.LinearLayoutCompat>

    <androidx.appcompat.widget.LinearLayoutCompat
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <androidx.appcompat.widget.AppCompatImageButton
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" />

        <androidx.appcompat.widget.AppCompatImageButton
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" />
    </androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.LinearLayoutCompat>

ConstraintLayout :

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.appcompat.widget.AppCompatImageButton
        android:id="@+id/ib1"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/ib3"
        app:layout_constraintEnd_toStartOf="@id/ib2"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.appcompat.widget.AppCompatImageButton
        android:id="@+id/ib2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/ib4"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@id/ib1"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.appcompat.widget.AppCompatImageButton
        android:id="@+id/ib3"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@id/ib2"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/ib1" />

    <androidx.appcompat.widget.AppCompatImageButton
        android:id="@+id/ib4"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@id/ib3"
        app:layout_constraintTop_toBottomOf="@+id/ib2" />
</androidx.constraintlayout.widget.ConstraintLayout>


来源:https://stackoverflow.com/questions/59389903/android-studio-4-button-on-full-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!