GridLayout动态添加子组件.layout_width和layout_height不起做用.

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完全没起作用.

可以使用 以下方式:
1.gridview 设置 columsNum
2.自定义子View(在onMeasure处设置其高为getMeasuredWidth的4/3)
3.为gridview编写adapter动态加载这些子view

试过.照着官方的api demo抄的代码.发现GridLayout的机制有问题.如果添加的组件没有默认的wrap content.会不显示.
如果是精确数值,第一个会自动划分自身的宽高给子组件.