How to position views/layout programmatically in a linear layout

Go To


Good day, I have a requirement which i need to include a layout (actually a custom Action_bar) to an already created layout (that was done in xml) depending on which intent is being sent. i.e if intent A sends, then include the layout. if intent B sends, don't.

i have successfully added the optional layout, by doing this:

layout = (LinearLayout)findViewById(;

                LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View view = inflater.inflate(R.layout.actionbar_layout, null, true);  //

but question is, how do i make it the first view in the layout?.. Please any help will be highly appreciated as always. Thanks

2012-04-04 17:43
by irobotxxx
I'm not sure why you are implementing your own actionbar but if its to add a uniform UX across all version of android consider checking out - slayton 2012-04-04 17:47
@slayton, i knew people will be wondering why am doing it. actually am using greendroid for it but the problem is i have tab activities that get populated from the listview, and greendroid has a different way of adding actionbar for both TabActivity and ListActivity. i end up having the actionbar display twice in the TabActivities because of the Listview.. so i had to create a custom own and use a normal Listactivity for only this particular case when the intent is not sent by the TabActivity - irobotxxx 2012-04-04 18:03


You can add the view using an index. For example, the first view will be index 0.

See the doc.

2012-04-04 17:55
by NitroG42
Thanks a lot!! funny missed that one - irobotxxx 2012-04-04 20:26