Android GridLayout Equal Column Widths

Just use column weight for GridLayout’s children:

android:layout_width="0dp"
android:layout_columnWeight="1"

Remember using support library if your project’s MinSdk < API 21:

implementation 'com.android.support:appcompat-v7:27.1.1' 
implementation 'com.android.support:gridlayout-v7:27.1.1'

You should use android.support.v7.widget.GridLayout instead of GridLayout.
And don’t forget using app namespace when using support library:

xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="0dp"
app:layout_columnWeight="1"

UPD:

If you make your GridLayout programmatically, use GridLayout.Spec. For example:

GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(
    GridLayout.spec(GridLayout.UNDEFINED, 1f),
    GridLayout.spec(GridLayout.UNDEFINED, 1f)
);

layoutParams.width = 0;

yourChildView.setLayoutParams(layoutParams);
yourGridLayout.addView(yourChildView);

(for every child view)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)