How to add views dynamically to a RelativeLayout already declared in the xml layout?

后端 未结 3 696
礼貌的吻别
礼貌的吻别 2020-12-01 14:44

I declared a RelativeLayout in a xml layout file. Now I want to add Views from code to the existing Layout. I added a Button dynamical

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-01 15:09

    Create another button:

    Button tv2 = new Button(this);
    tv2.setText("World");
    tv2.setLayoutParams(lprams);
    tv2.setId(2);
    

    Add add it into your RelativeLayout:

    rLayout.addView(tv2); 
    

提交回复
热议问题