gpt4 book ai didi

java - Android AdView 不可见 - 但可点击

转载 作者:行者123 更新时间:2023-12-02 05:41:27 29 4
gpt4 key购买 nike

我已经使用新的广告 sdk 创建了一个 Android 应用程序,但它是不可见的。我在以前的应用程序中让它工作,它在那里工作得很好。现在,在我的新应用程序中,我也做了同样的事情。但是:

AdView 不可见,但可点击。如果您返回主屏幕(只是最小化,不要停止!),然后重新打开它,就会显示广告。

我的 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.android.gms.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical" >

<org.andengine.opengl.view.RenderSurfaceView
android:id="@+id/SurfaceViewId"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:gravity="center" />

<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adViewId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adUnitId="XXX"
ads:adSize="BANNER" />

</RelativeLayout>

还有我的 onCreate 方法:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

adView = (AdView) findViewById(R.id.adViewId);

AdRequest adRequest = new AdRequest.Builder().build();

adView.loadAd(adRequest);

v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
}

编辑: 60 秒后, View 变得可见。

最佳答案

你的问题是你已经告诉你 RenderSurfaceView 来 matchParent 的高度。这意味着它将消耗其父级的所有空间,不会为 AdView 留下任何空间。

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.android.gms.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical" >

<org.andengine.opengl.view.RenderSurfaceView
android:id="@+id/SurfaceViewId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" />

<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adViewId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="XXX"
ads:adSize="BANNER" />

</LinearLayout>

这使用layout_weight和LinearLayout来让你的RenderSurfaceView展开以填充所有未使用的垂直空间。

关于java - Android AdView 不可见 - 但可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24479377/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com