Android 布局中的多个 Adview
我必须在布局中制作两个 AdView。布局的顶部和底部。我已经做了一个(顶部)。现在我想在布局的底部再添加一个 AdView。如何实现?提前致谢。我的布局中顶部 AdView 的代码如下。
@SuppressWarnings({ "deprecation", "unused" })
public class BannerEssentials extends Activity{
WebView webview;
static String MY_BANNER_UNIT_ID="google";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// BANNER 1
// Lookup R.layout.main
AbsoluteLayout layout = (AbsoluteLayout)findViewById(R.id.linearLayout);
// Create the adView
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
AdView adView = new AdView(this, AdSize.BANNER, MY_BANNER_UNIT_ID);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request)
I have to make of two AdViews in a layout. Both top and Bottom of a layout. I have done for one(the top). Now i want to make it one more AdView in the bottom of the layout. How to achieve it? Thanks in advance. My Code for top AdView in layout as follows.
@SuppressWarnings({ "deprecation", "unused" })
public class BannerEssentials extends Activity{
WebView webview;
static String MY_BANNER_UNIT_ID="google";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// BANNER 1
// Lookup R.layout.main
AbsoluteLayout layout = (AbsoluteLayout)findViewById(R.id.linearLayout);
// Create the adView
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
AdView adView = new AdView(this, AdSize.BANNER, MY_BANNER_UNIT_ID);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将另一个项目添加到线性布局,宽度=“fill_parent”,高度=“0dip”。然后设置权重=“1”。这应该具有将下面的任何东西推下去的效果。然后复制上面的代码以添加到新广告中。
您应该考虑在 XML 中定义视图,广告也可以直接通过 XML 插入,或者您也可以 定义您自己的自定义视图
Add another item to the linearlayout with width="fill_parent" and height="0dip". Then set the weight="1". This should have the effect of pushing whatever is below down. Then duplicate the code above to add in the new advertisement.
You should look into defining your views in XML, advertisements can also be inserted directly through XML or you could also define your own custom view