[英]Android: adding ad at bottom and shrinking the other view
我对Android布局还很陌生,我想在主视图的底部添加一个AdView,然后向上移动主视图,以缩小其高度。 我在某处添加了代码,使广告显示在底部,但是应用程序的高度并未缩小:广告占据了应用程序的底部。 我必须以编程方式使其没有xmls。
这是我的代码:
View mainView; // of type SurfaceView
adView = new AdView(this);
adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
adView.setAdSize(AdSize.SMART_BANNER);
mainLayout = new RelativeLayout(this);
mainLayout.addView(mainView);
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
mainLayout.addView(adView, adParams);
setContentView(mainLayout);
稍后,我显示adView:
adView.setVisibility(View.VISIBLE);
adView.loadAd(new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build());
提前致谢。
我对android也相当陌生,但是听起来您需要在adView中添加布局align标签。 那应该将应用程序推高并将添加项放在底部。 我希望这会有所帮助!
它是一个简单的:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_weight="1.0"/>
<LinearLayout
android:layout_height="60dp"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:layout_height="wrap_content"
android:text="add your ad here"
android:layout_width="wrap_content"/>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.