0
我想用不同的顏色動態添加四個相對佈局。當我嘗試添加該容器時,該容器包含四個子視圖。但三種佈局僅可見。如何使第一個佈局可見。在視圖組中動態添加布局
我的代碼
int[] colors={Color.RED,Color.BLACK,Color.BLUE,Color.YELLOW};
for(int i=0;i<4;i++){
RelativeLayout relativeLayout=new RelativeLayout(MainActivity.this);
relativeLayout.setId(i);
RelativeLayout.LayoutParams layoutParams=new RelativeLayout.LayoutParams(2400,100);
if(i>0){
layoutParams.addRule(RelativeLayout.BELOW,audioContainer.getChildAt(i-1).getId());
}
relativeLayout.setLayoutParams(layoutParams);
relativeLayout.setBackgroundColor(colors[i]);
audioContainer.addView(relativeLayout);
}
答案有幫助嗎? – brillenheini