add layout as a view in Android
I have a pretty complex layout defined in
xml file , now I want to add this layout as a view using
addView or something else.
As layout is pretty much complex , its pretty cumbersome process to write the code for layout and then add it as a view. So is there anyway to load layout
resource and add it as a view.
I want to add the layout into WebView
3 Solutions collect form web for “add layout as a view in Android”
LayoutInflater factory = LayoutInflater.from(this); View myView = factory.inflate(R.layout.my_layout_id, null);
U can also reduce this to oneline code;
View view = View.inflate(getActivity, R.layout.my_layout,null);
then add to your view.
If your view is a ViewGroup (layout)
You can use
InflaterService.inflate(id, ViewGroup) and set the ViewGroup, it will set the current child(s) with the content of your xml.