0
private void generateView() {
    for (int i = 0; i < 10; i++) {
        mview = new LinearLayout(getActivity());
        mview.setBackgroundResource(R.color.grayColor);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(10, 40);
        layoutParams.setMargins(5, 0, 5, 0);
        mview.setLayoutParams(layoutParams);
        lnLinearlayout.addView(mview);
    }
}

使用此代码,我可以显示如下视图:

||||||||||

我想增加位置 4 和 8 的视图高度。我正在尝试使用:

lnLinearlayout.getChildAt(4).setMinimumHeight(20) lnLinearlayout.getChildAt(8).setMinimumHeight(20)

但观点没有变化。谁能建议如何增加特定视图的高度?

4

2 回答 2

1

使用下面的代码..

 LinearLayout.LayoutParams layoutParams=(LinearLayout.LayoutParams)lnLinearlayout.getChildAt(4).getLayoutParams();
    layoutParams.height=20;
    layoutParams=(LinearLayout.LayoutParams)lnLinearlayout.getChildAt(8).getLayoutParams();
    layoutParams.height=20;
于 2017-07-26T12:52:56.027 回答
0

尝试这个

lnLinearlayout.getChildAt(4).setLayoutParams(new LinearLayout.LayoutParams(10, 200));
于 2017-07-26T12:40:04.873 回答