Create View-Object from XML file in android

我与影子孤独终老i 提交于 2019-12-03 22:19:16

You should change your line to:

LayoutInflater.from(context).inflate(R.layout.myfile, null);

You can find it in documentation here.

LayoutInflater.from(context).inflate(R.layout.myfile, myparent, true);

The end parameter determines whether or not to automatically add the new view to myparent. Turn it to false to still use the parent's layout attributes.

Or, if you don't care about the parent's layout params, follow @inazaruk's answer

You could make this component invisible with:

android:visibility="gone"

Source: http://developer.android.com/reference/android/view/View.html#attr_android:visibility

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!