Creating LinearLayout Programmatically/Dynamically with Multiple Views

前端 未结 4 1215
太阳男子
太阳男子 2020-12-05 09:46

I have a hierarchy that is like this:

  • LinearLayout(horizontal)
    • ImageView
    • LinearLayout(vertical)
      • TextView
      • TextView
4条回答
  •  执笔经年
    2020-12-05 10:27

    The problem is because the views are already added to the layout in the XML file. Then you findViewById (find them) and try to add them to the layout again. That is why the app crashes complaining that, view already has a parent and you can't add it again.

提交回复
热议问题