Reputation: 63
I'm trying to create a 4*n grid where each attribute within the grid has a textView saying "1" then directly underneath that text view saying "One"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="4"
android:rowCount="2">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:textSize="30dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="One"
android:textSize="32sp" />
</GridLayout>
This just provides each text view next to each other in a grid.
Any help would be greatly appreciated.
Thank you.
Upvotes: 0
Views: 41
Reputation: 2746
you should create your row layout file like this,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:textSize="30dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="One"
android:textSize="32sp" />
</LinearLayout>
inflate this row file in the adapter and set the not of items in each row for grid to 4.
one suggestion - user recyclerview with GridLayoutManager instead of GridLayout.
Upvotes: 2