android dynamically add layouts under each other

前端 未结 2 1946
失恋的感觉
失恋的感觉 2021-01-07 01:38

I\'m trying to add multiple layouts dynamically under each other. So I wrote the following code:

   for (int i = 1; i <= layoutCounter; i++) {
        Vie         


        
2条回答
  •  逝去的感伤
    2021-01-07 02:34

    You can try like this

    RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(...)
    
    
    rl.addRule(RelativeLayout.BELOW, anotherview.getId())
    rl.addRule(RelativeLayout.ALIGN_PARENT_LEFT)
    
    parentLayout.addView(myView, rl)
    

提交回复
热议问题