How to use addView to add view to layout?

后端 未结 4 2187
南笙
南笙 2021-02-18 16:36

I have read probably all posts and documentation but I still can\'t solve this issue.

I want to use addView() method to add view to the existing (running) l

4条回答
  •  别跟我提以往
    2021-02-18 17:02

    I had the same problem and wasted several time finding the reason.

    My fault was that I was adding a CustomView that had match_parent set as height.

    I hope to save some precious time to anybody who did this silly annoying mistake :)

    TextView tv = new TextView(this);
    lytMarks.addView(tv);
    
    
    CustomView cv = new CustomView(this, someObject);
    lytMarks.addView(cv); // <-- This one had height = match_parent!!
    
    
    EditText et = new EditText(this);
    lytMarks.addView(et);
    

提交回复
热议问题