android:id="@+id/recycler_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/dimen_2X"
android:paddingRight="@dimen/dimen_2X"
android:columnCount="5"
>
gridLayout.post(new Runnable() {
@Override
public void run() {
int width = (gridLayout.getWidth() - 2 * gridLayout.getPaddingLeft()) / COLUMNCOUNT;
int height = (int) (width / 0.75f);
MyLogger.jLog().i(width + ":" + height);
for (int i = 0; i < FAVORITCOUNT; i++) {
TextView colorCardView = new TextView(getApplicationContext());
colorCardView.setBackgroundColor(Color.WHITE );
GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams();
layoutParams.width = width;
layoutParams.height = height;
colorCardView.setLayoutParams(layoutParams);
gridLayout.addView(colorCardView);
}
}
});
需求是在Gridlayout中显示25个子组件.每行5个.每个组件宽高比是3:4.
在log中已经能获取到宽高98,130.
但实际显示中,子组件的宽为父布局宽,高为宽的4/3.所有子组件重叠在一起.
感觉params.width和height完全没起作用.