joe
joe

Reputation: 17478

LinearLayout add a view above the other views Android

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

Answers (2)

Viacheslav
Viacheslav

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

mango
mango

Reputation: 5636

you can specify at what index you want to addView at.

layout.addView(child, index);

Upvotes: 11

Related Questions