求教:
需要動態添加linearLayout,但是沒成功,卡到這了請高手相助。謝謝
LinearLayout parentLayout = (LinearLayout)findViewById(R.id.parentLayout);
lLayout = new LinearLayout[8];
for(int i = 0; i < lLayout.length; i++) {
lLayout[i] = new LinearLayout(this);
lLayout[i].setId(i);
lLayout[i].setOrientation(LinearLayout.HORIZONTAL);
if(i%2 == 0) {
lLayout[i].setBackgroundColor(Color.GREEN);
} else {
lLayout[i].setBackgroundColor(Color.MAGENTA);
}
parentLayout.addView(lLayout[i]);
}
lLayout[i]
調用一下setLayoutParams方法配置一下寬高試試