Why does LayoutInflater ignore the layout_width and layout_height layout parameters I've specified?

前端 未结 3 1771
终归单人心
终归单人心 2020-11-22 12:59

I\'ve had severe trouble getting LayoutInflater to work as expected, and so did other people: How to use layoutinflator to add views at runtime?.

Why does LayoutInfl

3条回答
  •  长情又很酷
    2020-11-22 13:16

    andig is correct that a common reason for LayoutInflater ignoring your layout_params would be because a root was not specified. Many people think you can pass in null for root. This is acceptable for a few scenarios such as a dialog, where you don't have access to root at the time of creation. A good rule to follow, however, is that if you have root, give it to LayoutInflater.

    I wrote an in-depth blog post about this that you can check out here:

    https://www.bignerdranch.com/blog/understanding-androids-layoutinflater-inflate/

提交回复
热议问题