[英]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? 如何更新此代码,以便我的adView位于我的应用顶部?
您可以指定要添加addView
索引。
layout.addView(child, index);
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. 您可以使用以下方法之一:1)添加空的
LinearLayout
以放置您要显示广告的位置,然后将adView
添加到它们。 2) add adView
in you xml-layout(if it possible) and hide/show them when you need by using setVisible()
method. 2)在xml-layout中添加
adView
(如果可能),并在需要时使用setVisible()
方法隐藏/显示它们。
Also you can use RelativeLayout
instead LinearLayout
but it harder to add View to them dynamically. 您也可以使用
RelativeLayout
而不是LinearLayout
但更难以动态地向它们添加View。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.