ViewStub'parent viewgroup

余生颓废 提交于 2019-12-02 09:46:25

Your ViewStub don't have a parent, that's why you catch Exception. You must add ViewStub in Layout at first, after you can inflate it to another View.

Why you use ViewStub? Do you really need it? Maybe it can be good solution:

try {
    View.inflate(getApplicationContext(), R.layout.view_stub_layout, mainLayout);
} catch(Exception e){
    e.getMessage();
}

If you need to keep added Views:

try {
    views[i] = View.inflate(getApplicationContext(), R.layout.view_stub_layout, null);
    mainLayout.add(views[i]);
} catch(Exception e){
    e.getMessage();
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!