adView
是AdMob的视图,我将其添加到另一个框架视图中,如下所示:
adView = new AdView(this);
RelativeLayout relativeLayout = new RelativeLayout(this);
mFrameLayout.addView(relativeLayout);
RelativeLayout.LayoutParams adViewParams = new RelativeLayout.LayoutParams(
AdView.LayoutParams.WRAP_CONTENT,
AdView.LayoutParams.WRAP_CONTENT);
//important I use this to make it appear on the bottom
adViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
relativeLayout.addView(adView, adViewParams);
它出现在框架布局的底部,因此位于屏幕的底部(框架布局是我的屏幕)。但是不是在中心,它是左对齐的。如何对RelativeLayout
中的FrameLayout
进行对齐。
EIDT:如果你需要它,这是FrameLayout:
// FrameLayout
ViewGroup.LayoutParams framelayout_params =
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
mFrameLayout = new FrameLayout(this);
mFrameLayout.setLayoutParams(framelayout_params);
答案 0 :(得分:1)
我做到了这一点它有效:
adViewParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
请确认是否正确。