改变布局后,admob消失了

时间:2013-03-10 17:35:06

标签: android admob

我在我的android应用程序中使用多个布局。当我通过setContentView更改布局时,admob banner就会消失。在更改布局时我还需要做任何事情。

public void setContentView (int layoutResID) 
    {
        super.setContentView(layoutResID);
        // Create the adView
        try {
            // Lookup your LinearLayout assuming it's been given
            // the attribute android:id="@+id/mainLayout"

        RelativeLayout layout = (RelativeLayout)
                findViewById(getRespectiveLayoutID(layoutResID));
        //adView.setGravity(Gravity.BOTTOM);
        // Add the adView to it
        layout.addView(adView);

        // Initiate a generic request to load it with an ad

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

`我真的很感激任何帮助

1 个答案:

答案 0 :(得分:1)

更改布局后,您需要将广告添加到新布局中。 adview是一个视图,就像文本视图一样,所以上面的代码正在做的是将adview添加到布局中。当您致电setContentView(R.layout.example)时,您会更改视图,因此无法看到广告视图,因为它未显示。要解决此问题,您必须在您调用的每个setContentView之后放置您编写的代码。

相关问题