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)
但视图中没有变化。任何人都可以建议如何增加特定视图的高度?
答案 0 :(得分:1)
使用以下代码..
LinearLayout.LayoutParams layoutParams=(LinearLayout.LayoutParams)lnLinearlayout.getChildAt(4).getLayoutParams();
layoutParams.height=20;
layoutParams=(LinearLayout.LayoutParams)lnLinearlayout.getChildAt(8).getLayoutParams();
layoutParams.height=20;
答案 1 :(得分:0)
试试这个
lnLinearlayout.getChildAt(4).setLayoutParams(new LinearLayout.LayoutParams(10, 200));