开发者

Add view to XML layout programmatically and make its z order below an existing view

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


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

Edit: Google seem have to moved the android developer from their android page to blogspot.

Updated Link: http://android-developers.blogspot.com/2009/03/android-layout-tricks-3-optimize-with.html


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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜