• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Inflating layout XML files and layout parameters

BobPaul

Well-Known Member
OK, when I inflate a layout XML file and add it to another view everything works OK
save for one thing. The Layout param's in the XML don't seem to be utilized.

Layout in question is myeditview below and its XML has layout width set
to fill parent.

Here is some sample code which causes the inflated view to behave
as tho it is specified to constrict to content size.

View tmpView;
LayoutInflater li;

li = (LayoutInflater)tenantsTabActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
tmpView = li.inflate(R.layout.myeditview, null);


thisTabsContentLayout.removeAllViews();
thisTabsContentLayout.addView(tmpView);



Here is the sample code that sets the layout parm's explicitely and works as expected.

View tmpView;
LayoutInflater li;

li = (LayoutInflater)tenantsTabActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
tmpView = li.inflate(R.layout.myeditview, null);
LayoutParams lp = new LayoutParams(-1,-2);
tmpView.setLayoutParams(lp);

thisTabsContentLayout.removeAllViews();
thisTabsContentLayout.addView(tmpView);


Anyone else have this problem? Is there a known way to cause the XML to
correctly set the Layout Parms? I really hate to have to bury this into
the Java code. So much better to keep it in the layout definitions.
 
Back
Top Bottom