Sat. Jan 4th, 2025

ConstraintLayout offers more flexibility and better performance for complex layouts

<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF9800"
tools:context=".MainActivity">

<Button
android:id="@+id/bt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:layout_margin="5dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/bt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:layout_margin="5dp"
app:layout_constraintStart_toEndOf="@id/bt1"
app:layout_constraintTop_toTopOf="@id/bt1" />

<Button
android:id="@+id/bt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:layout_margin="5dp"
app:layout_constraintStart_toEndOf="@id/bt2"
app:layout_constraintTop_toTopOf="@id/bt2" />

<Button
android:id="@+id/bt4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:layout_margin="5dp"
app:layout_constraintStart_toEndOf="@id/bt1"
app:layout_constraintTop_toBottomOf="@id/bt2" />

<Button
android:id="@+id/bt5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:layout_margin="5dp"
app:layout_constraintEnd_toStartOf="@id/bt3"
app:layout_constraintTop_toBottomOf="@id/bt4" />

<Button
android:id="@+id/bt6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:layout_margin="5dp"
app:layout_constraintEnd_toStartOf="@id/bt3"
app:layout_constraintTop_toBottomOf="@id/bt5" />

<Button
android:id="@+id/bt7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="7"
android:layout_margin="5dp"
app:layout_constraintTop_toBottomOf="@id/bt6" />

<Button
android:id="@+id/bt8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:layout_margin="5dp"
app:layout_constraintTop_toBottomOf="@id/bt7"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/bt9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:layout_margin="5dp"
app:layout_constraintTop_toBottomOf="@id/bt8"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/bt10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/bt11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="11"
android:layout_margin="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/bt12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12"
android:layout_margin="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/bt13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="13"
android:layout_margin="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/bt14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="14"
android:layout_margin="5dp"
app:layout_constraintTop_toBottomOf="@id/bt9"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

By Rajashekar

I’m (Rajashekar) a core Android developer with complimenting skills as a web developer from India. I cherish taking up complex problems and turning them into beautiful interfaces. My love for decrypting the logic and structure of coding keeps me pushing towards writing elegant and proficient code, whether it is Android, PHP, Flutter or any other platforms. You would find me involved in cuisines, reading, travelling during my leisure hours.

Leave a Reply

Your email address will not be published. Required fields are marked *