Adding a view to a LinearLayout at a specified position

后端 未结 6 889
[愿得一人]
[愿得一人] 2020-12-25 09:52

I have the following main.xml file with a LinearLayout




        
6条回答
  •  隐瞒了意图╮
    2020-12-25 10:27

    I faced a similar problem. In my case I wanted to add a LinearLayout at last position of another LinearLayout. To accomplish it, I did:

    LinearLayout parentLayout = (LinearLayout) findViewById(R.id.parentLayout);
    LinearLayout layout = new LinearLayout(this);
    layout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    
    // add others views to your linear layout
    
    parentLayout.addView(layout, parentLayout.getChildCount());
    

提交回复
热议问题