GridLayout Column width
This code is available on pre API21 with support library!
I have a simple piece of code to show 4 buttons in a gridLayout of 2 columns that take 50% of the available space: perhaps it can help
<GridLayout
android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="2"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_gravity="fill"
android:layout_columnWeight="1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_gravity="fill"
android:layout_columnWeight="1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_gravity="fill"
android:layout_columnWeight="1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_gravity="fill"
android:layout_columnWeight="1"
/>
</GridLayout>
Solution is perhaps this :
android:layout_gravity="fill"
android:layout_columnWeight="1"
For pre API 21, use support library:
add
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
to your dependencies.
Then in your xml file:
<android.support.v7.widget.GridLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:columnCount="2"
app:orientation="horizontal"
app:rowCount="1">
<TextView
android:text="1"
android:textStyle="bold"
app:layout_columnWeight="1"
/>
<TextView
android:text="2"
android:textStyle="bold"
app:layout_columnWeight="1" />
</android.support.v7.widget.GridLayout>
Here note the use of "app" prefix and dont forget to add
xmlns:app="http://schemas.android.com/apk/res-auto"
to your xml file