tags:

views:

58

answers:

2

I have an XML layout with some custom tabs, a heading, and a ProgressBar(main.xml). I wish to add another XML layout(home.xml) to the main.xml layout, as i wish to keep main.xml re-usable for other activity's layouts and simply add things to it as necessary.

home.xml contains a ScrollView and a TextView. I am currently using my Activity's LayoutInflator to add home.xml to main.xml:

LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.home, rootLayout);

rootLayout is the root layout of main.xml and is a RelativeLayout

The problem: after inflating R.layout.home into rootLayout, it seems as though the ProgressBar contained in rootLayout is hidden underneath the content of home.xml

Is there a way to tell certain views(via XML) to float above other views when the layout is constructed in this way?

if not, am i forced to use methods such as progressBar.bringToFront() to raise targeted views to the top?

what alternatives do i have in z-ordering views when some layouts are constructed using inflation?

edit: it seems as though the bringToFront() method is not doing what i expect - i call it on one of my Button views and it still appears to be ordered below all other views(which were inflated) and remains unclickable

+2  A: 

Views are drawn based on their order in the parent. For instance, the child at index 0 is always (at least with the current layouts, except Gallery) drawn first and the child at index count - 1 is always drawn last. bringToFront() simply moves a View from its current position in the parent to the last. Note that changing the index of a child can affect its position on screen (for instance in a horizontal LinearLayout, moving a child from index 0 to index count - 1 will also move it from the far left to the far right.)

Romain Guy
+1  A: 

You could try using ViewStub instead of manually adding it and set the set the inflateId with setInflateId(R.layout.home)

http://developer.android.com/resources/articles/layout-tricks-stubs.html

Tseng
this worked PERFECTLY!! thanks! my first time using a `ViewStub`, now i can see what they're good for
binnyb