dynamically adding a view to activity layout

后端 未结 1 653
青春惊慌失措
青春惊慌失措 2021-01-18 02:51

I have a custom view (an extension of a TextView) that I want to dynamically add to my Layout (don\'t want to include it in the main.xml file).

The book says to fetc

相关标签:
1条回答
  • 2021-01-18 03:36

    Please post your code where you add the view. But yes, you might be missing the params for width and height. Try something like

    LayoutParams p = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.FILL_PARENT);    
    txtView.setLayoutParams(p);
    

    or what you would like the width and height to be. Also in xml layout, layout_width and layout_height are required attributes.

    0 讨论(0)
提交回复
热议问题