In Grid layout, you can divide your screen in rows and column to make your layout more attractive. Grid layout is mostly used in photo Gallery and others things where Grids are used.
The GridLayout is a new ViewGroup subclass that supports laying out views in a 2D grid, similar to an HTML table, as shown below:
Example:-
<?xml version="1.0" encoding="utf-8"?>
<GridLayout 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:columnCount="2"
android:rowCount="3">
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_columnSpan="2"
android:background="#F44336"
android:textSize="70sp"
android:text="1st" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#2196F3"
android:textSize="70sp"
android:text="2nd" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_rowSpan="2"
android:background="#4CAF50"
android:textSize="70sp"
android:text="3rd" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#FFC107"
android:textSize="70sp"
android:text="4th" />
</GridLayout>
<GridLayout 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:columnCount="2"
android:rowCount="3">
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_columnSpan="2"
android:background="#F44336"
android:textSize="70sp"
android:text="1st" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#2196F3"
android:textSize="70sp"
android:text="2nd" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_rowSpan="2"
android:background="#4CAF50"
android:textSize="70sp"
android:text="3rd" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#FFC107"
android:textSize="70sp"
android:text="4th" />
</GridLayout>
No comments:
Post a Comment