在LayoutParams中设置横幅位置

时间:2015-01-31 06:03:51

标签: android

我尝试在我的oncreate中添加adView横幅。 但是它会离开屏幕顶部,我使用大多数参数来改变位置到中心按钮,但它不会移动任何原因。

            RelativeLayout.LayoutParams  adParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
            adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            adView = new AdView(this);
            adView.setToken("xxxxxxxxxxxxxxxxxxxxxxxx");

            addContentView(adView, adParams);

1 个答案:

答案 0 :(得分:0)

尝试重力'参数:

 FrameLayout.LayoutParams adParams = new  
 FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT
                        , LayoutParams.WRAP_CONTENT);
 adParams.gravity = Gravity.CENTER;

 adView = new AdView(this);
 adView.setToken("xxxxxxxxxxxxxxxxxxxxxxxx");
 addContentView(adView, adParams);