我正在尝试实现横幅广告,但它弄乱了我的主要布局,即 DrawView。要么显示 mAdview,要么显示 DrawView,但不能一起显示。我想一起展示它们。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
size = getIntent().getIntExtra("SIZE", 3);
setContentView(R.layout.activity_tile);
drawView = new DrawView(this, size);
setContentView(drawView);
setTileSize();
MobileAds.initialize(this, "ca-app-pub-3940256099942544/6300978111");
mAdView = findViewById(R.id.adView);
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
}
创建的 XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<view class="com.kilnake.patta.picpuzz.TileActivity$DrawView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"/>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111" />
</LinearLayout>