android 随笔之 GridLayout

mGridLayout = (GridLayout) findViewById(R.id.gridLayout);
columnCount = mGridLayout.getColumnCount();
screenWidth = this.getWindowManager().getDefaultDisplay().getWidth();//获取手机屏幕宽度
Log.e(TAG, "column:" + columnCount + "; screen" + screenWidth);
for (int i = 0; i < mGridLayout.getChildCount(); i++) {
Button button = (Button) mGridLayout.getChildAt(i);
button.setWidth(screenWidth / columnCount);
}

原文地址:https://www.cnblogs.com/aliceQin/p/10887132.html