I am trying to use GridLayout and am having trouble expanding the rows (with TextViews) to "fill-up" the space in the layout.
Vertical Picture (note red line is where rows should expand):
Horizontal Picture:
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2"
android:useDefaultMargins="true" >
<TextView
style="@android:style/TextAppearance.Large"
android:layout_columnSpan="2"
android:layout_gravity="center_horizontal"
android:padding="8dp"
android:text="Which means: lacking in originality as to be obvious and boring." />
<Space android:layout_height="24dp" android:layout_columnSpan="2" />
<TextView style="@style/AnswerLetter" android:text="A." />
<TextView style="@style/AnswerChoice" android:text="ascetic" />
<TextView style="@style/AnswerLetter" android:text="B." />
<TextView style="@style/AnswerChoice" android:text="banal" />
<TextView style="@style/AnswerLetter" android:text="C." />
<TextView style="@style/AnswerChoice" android:text="contraption" />
<TextView style="@style/AnswerLetter" android:text="D." />
<TextView style="@style/AnswerChoice" android:text="dominion" />
<TextView style="@style/AnswerLetter" android:text="E." />
<TextView style="@style/AnswerChoice" android:text="enervation" />
</GridLayout>
styles.xml:
<style name="AnswerLetter" parent="@android:style/TextAppearance.Medium">
<item name="android:layout_gravity">right</item>
<item name="android:paddingLeft">32dp</item>
<item name="android:textStyle">bold</item>
<item name="android:gravity">center_vertical|center_horizontal</item>
</style>
<style name="AnswerChoice" parent="@android:style/TextAppearance.Large">
<item name="android:layout_gravity">left</item>
<item name="android:paddingLeft">32dp</item>
<item name="android:gravity">left</item>
</style>
Select the row or rows that you want to change. On the Home tab, in the Cells group, click Format. Under Cell Size, click AutoFit Row Height. Tip: To quickly autofit all rows on the worksheet, click the Select All button, and then double-click the boundary below one of the row headings.
First, (1) select multiple rows by clicking on a row number and dragging down to the last row you want to resize. OR hold CTRL and click on the rows number you want to select (e.g., 1–10). After that, (2) right-click anywhere in the selected area, and (3) choose Resize rows 1 – 10.
You want all your child subviews to grow (in height) in order to fill out that extra space, but that's not possible inside a GridLayout:
GridLayout does not provide support for the principle of weight, as defined in weight. In general, it is not therefore possible to configure a GridLayout to distribute excess space in non-trivial proportions between multiple rows or columns ... For complete control over excess space distribution in a row or column; use a LinearLayout subview to hold the components in the associated cell group."
Try adding a linear layout as a subview and setting the weight attributes of all children to the same value (so they expand equally).
Similar question: GridLayout (not GridView) how to stretch all children evenly
If i understand you correctly - this layout can solve your problem. GridView can't strech column hight, so you can use LinearLayout. I make this layout for you, maybye it needs some padding adjustments
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/LinearLayout1"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
style="@android:style/TextAppearance.Large"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="8dp"
android:text="Which means: lacking in originality as to be obvious and boring." />
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:layout_height="wrap_content">
<TextView
style="@style/AnswerLetter"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="A." />
<TextView
style="@style/AnswerChoice"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="ascetic" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:gravity="center_vertical"
android:layout_weight="1"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
style="@style/AnswerLetter"
android:text="B." />
<TextView
style="@style/AnswerChoice"
android:layout_width="match_parent"
android:gravity="center_vertical"
android:layout_height="match_parent"
android:text="banal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:gravity="center_vertical"
android:layout_weight="1"
android:layout_height="wrap_content">
<TextView
style="@style/AnswerLetter"
android:layout_width="wrap_content"
android:gravity="center_vertical"
android:layout_height="match_parent"
android:text="C." />
<TextView
style="@style/AnswerChoice"
android:layout_width="match_parent"
android:gravity="center_vertical"
android:layout_height="match_parent"
android:text="contraption" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:gravity="center_vertical"
android:layout_weight="1"
android:layout_height="wrap_content">
<TextView
style="@style/AnswerLetter"
android:layout_width="wrap_content"
android:gravity="center_vertical"
android:layout_height="match_parent"
android:text="D." />
<TextView
style="@style/AnswerChoice"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="dominion" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:gravity="center_vertical"
android:layout_weight="1"
android:layout_height="wrap_content">
<TextView
style="@style/AnswerLetter"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="E." />
<TextView
style="@style/AnswerChoice"
android:layout_width="match_parent"
android:gravity="center_vertical"
android:layout_height="match_parent"
android:text="enervation" />
</LinearLayout>
</LinearLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With