Reputation: 17478
I would like to add a view to the top of my linear layout. The following code is adding my view to the end of the application layout.
LinearLayout layout = (LinearLayout)findViewById(R.id.root);
layout.addView(adView);
How do I update this code so that my adView is at the top of my app?
Upvotes: 3
Views: 3010
Reputation: 5593
You can use one of these approaches:
1) add an empty LinearLayout
to place where you want to show Ad and then add adView
to them.
2) add adView
in you xml-layout(if it possible) and hide/show them when you need by using setVisible()
method.
Also you can use RelativeLayout
instead LinearLayout
but it harder to add View to them dynamically.
Upvotes: 1
Reputation: 5636
you can specify at what index you want to addView
at.
layout.addView(child, index);
Upvotes: 11