android dynamically add layouts under each other

前端 未结 2 1945
失恋的感觉
失恋的感觉 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:17

    Maybe with:

    params.addRule(RelativeLayout.BELOW, layoutID-1);

    instead of:

    params.addRule(RelativeLayout.BELOW, neu.getId());

    in your else condition.

    0 讨论(0)
  • 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)
    
    0 讨论(0)
提交回复
热议问题