开发者

How to place adView below?

I create a game which has a custom view derived from surfaceView. and in the game I want to place adView below the gameView. but the problem is , if I place adView below the gameView , the adView wont show up.. I do all the layouting in the code because its easier to maintain..

here is the code..

If i place the adView above the gameView it will show up

private RelativeLayout layout;   //the gameView container
private LinearLayout mainLayout;  //the main layout
private RocketView rocketView;   //the gameView
private AdView adView;             //the adView
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

        mainLayout = new LinearLayout(this);
        mainLayout.setOrientation(LinearLayout.VERTICAL);

        adView = new AdView(this, AdSize.BANNER, "a14d9e9ea3740e8");
       开发者_JAVA百科 adView.setVisibility(AdView.VISIBLE);
        adView.loadAd(new AdRequest());
        mainLayout.addView(adView);   // -->> here i place the adView first

        layout = new RelativeLayout(this);
        mainLayout.addView(layout);   //--->> then i place the gameView later

        rocketView = new RocketView(this);
        layout.addView(rocketView);
        setContentView(mainLayout);
}

But if i place the adView below it won't show up.

private RelativeLayout layout;
private LinearLayout mainLayout;
private RocketView rocketView;
private Launcher launcher;

private AdView adView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        mainLayout = new LinearLayout(this);
        mainLayout.setOrientation(LinearLayout.VERTICAL);

        layout = new RelativeLayout(this);
        mainLayout.addView(layout);

        rocketView = new RocketView(this);
        layout.addView(rocketView);

        adView = new AdView(this, AdSize.BANNER, "a14d9e9ea3740e8");
        adView.setVisibility(AdView.VISIBLE);
        adView.loadAd(new AdRequest());
        mainLayout.addView(adView);
        setContentView(mainLayout);

}

I think I know what happen.. after adView loading the adRequest and get the ads, its not streching above, but it streching below, so it not showing in the screen. but I don't know how to solve this problem. please help me..


First, there is no need for your linear layout, mainLayout. Add both rocketView and adView to your relativelayout, layout. Give adView the attributes align_parent_bottom, wrap_content (height) and wrap_content or fill_parent for width. Then give rocketView fill_parent for width and height and have it be "above" adView.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜