I have a GridView
in a vertical LinearLayout
, that I want to have take up all remaining vertical space. The grid will always have 5 columns and 7 rows. The grid items are just a TextView
. I want the grid items to expand proportionally (so that each item is one fifth of the width and one seventh of the height) to fill remaining space on any device. I tried setting layout weights, but that didn't do anything.
How can I make it fill the space?
Here's my activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<TextView
android:text="@string/zero"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv0"
android:gravity="end"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:paddingEnd="8dp"
android:paddingStart="8dp"
android:textColor="#e4e4e4"
android:background="@color/colorPrimaryDark"/>
<!-- A few more TextViews -->
<GridView
android:id="@+id/grid_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:horizontalSpacing="0dp"
android:verticalSpacing="0dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:numColumns="5"/>
</LinearLayout>
And here's the layout for the grid item:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@color/colorPrimary"
android:paddingBottom="15dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="15dp"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"/>
</FrameLayout>