Is index important in addView()?

来源:互联网 发布:java格式化日期 编辑:程序博客网 时间:2024/06/06 14:18

http://stackoverflow.com/questions/21578170/is-index-important-in-addview

Is index important in addView()?

up vote0 down vote favorite

I can't understand the function of index in addView(View child, int index) of aViewGroup.What's the index for? Can be index negative value? Does it affect to thelayout or the way to display the view?I have tested the code with and withoutindex and I can't see the difference.

share|improve this question
 

1 Answer

activeoldest votes
up vote0 down vote accepted

The point of the index attribute is to allow you change the order of views.

Let's say you have a massive list of views, and want to suddenly put one at the very top. If you specify that view's index as 0, it will be the first to display in the layout.

The Android documentation talks briefly about this.

A previous SO question shows the practical use for this: Android: How to add view at start of layout?.

Unless you really need to specify a position for the view, just use addView(view).

share|improve this answer
 
 
So, the order and position means Z-order? I mean, which view is above another? – Fran Feb 5 at 14:07
 
@Fran You could say that. It's like the order in which they're displayed.0 is before 1, and 5 is after 4 in the display order. 0 will be at the top (or left), and the highest number at the bottom (or right). – Joe Boyle Feb 5 at 14:16

0 0
原创粉丝点击