How to use layoutinflator to add views at runtime?

前端 未结 2 1646
感动是毒
感动是毒 2020-12-09 20:49

I have two layouts: main.xml and buttonpanel.xml. In buttonpanel.xml, in main linearlayout I set gravity to bottom. Now i am trying to add the buttonpanel layout using the

相关标签:
2条回答
  • 2020-12-09 21:21

    I have had problems with layout parameters being dropped when inflating views in the way that you are doing it. If I use a slightly different call to inflate my layout parameters are respected:

    parent_view = inflater.inflate(R.layout.buttonpanel, parent);
    

    Or in my case, when the parent did not support adding views to it:

    view = inflater.inflate(R.layout.buttonpanel, parent, false);
    

    Perhaps this will solve your problem as well.

    EDIT: Different views are returned depending on what parameters are given. LayoutInflater

    0 讨论(0)
  • 2020-12-09 21:32

    you can use childview index for setting it. i think it will help you.try another method for addview which include childindex

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