Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 568
Hunt Avatar asked Jun 24 '11 08:06

Hunt


2 Answers

Use

LayoutInflater factory = LayoutInflater.from(this);
View myView = factory.inflate(R.layout.my_layout_id, null);

then use addView(myView)

like image 121
Ramya K Sharma Avatar answered Oct 23 '22 11:10

Ramya K Sharma


U can also reduce this to oneline code;

  View view = View.inflate(getActivity, R.layout.my_layout,null);

then add to your view.

like image 38
Raja Jawahar Avatar answered Oct 23 '22 10:10

Raja Jawahar