我有一个屏幕,我有2个全屏视图,我想在底部有一个adwhirl广告。
这是我的xml文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:id="@+id/main_layout"
>
</RelativeLayout>
然后我从代码中将视图放在上面:
// in activity's onCreate
RelativeLayout layout = (RelativeLayout)findViewById(R.id.main_layout);
v1= new V1(this);
v2= new V2(this, v1);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
v1.setLayoutParams(lp);
v2.setLayoutParams(lp);
layout.addView(v1);
layout.addView(v2);
.....
AdWhirlLayout adWhirlLayout2 = new AdWhirlLayout(this, "key");
adWhirlLayout2.setAdWhirlInterface(this);
adWhirlLayout2.setMaxWidth(width);
adWhirlLayout2.setMaxHeight(height);
RelativeLayout.LayoutParams lp_bottom = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp_bottom.addRule(RelativeLayout.ALIGN_BOTTOM, RelativeLayout.TRUE);
adWhirlLayout2.setLayoutParams(lp_bottom);
layout.addView(adWhirlLayout2);
但广告仍然位于屏幕顶部,就像我没有设置布局框架一样。
答案 0 :(得分:0)
尝试:
lp_bottom.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);