假设您已访问网格视图:
final GridView gw = [...];
要设置上面的所有属性,您应该写:
// This line applies to a GridView that you've just created
gv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
// The next two lines are for a GridView that you already have displayed
gv.getLayoutParams().width = LayoutParams.FILL_PARENT;
gv.getLayoutParams().height = LayoutParams.FILL_PARENT;
gv.setNumColumns(GridView.AUTO_FIT);
gv.setVerticalSpacing(convertFromDp(10));
gv.setHorizontalSpacing(convertFromDp(10));
gv.setColumnWidth(convertFromDp(90));
gv.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
gv.setGravity(Gravity.CENTER);
要设置LayoutParams,您必须在上述两种情况之间进行选择.