广告并未触底

时间:2011-08-03 11:23:35

标签: android xml android-layout

我有关于广告对齐的问题。广告正在应用程序的顶部,但我需要它在应用程序的底部。我没有在java中直接尝试过广告的任何布局。它的工作正常,但只有在我插入adView.setGravity(Gravity.BOTTOM)之后它才会出现在顶部; 代码如下        //查找R.layout.main

    RelativeLayout layout = (RelativeLayout)findViewById(R.id.relativeLayout);


    // Create the adView
    // Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
    AdView adView = new AdView(this, AdSize.BANNER, "a14e36b9902bfcc");

    // 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);  
    adView.setGravity(Gravity.BOTTOM);

2 个答案:

答案 0 :(得分:2)

您需要将LayoutParams的{​​{1}}设置为:

RelativeLayout

答案 1 :(得分:1)

将视图添加到相对布局

时指定参数

更改

    // Add the adView to it
    layout.addView(adView);

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_BOTTOM, RelativeLayout.TRUE); 
    layout.addView(adView,params);