【问题标题】:Can't get admobs ad to show up at the bottom无法让 admobs 广告显示在底部
【发布时间】:2014-04-30 20:25:16
【问题描述】:

我在 Google 和 stackoverflow 上进行了搜索,浏览了所有问题和答案,但似乎没有什么对我有用。广告仍然显示在我的活动底部。 有谁知道我做错了什么?

public class MainActivity extends Activity {
String[] myItems;
RelativeLayout RelLay;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menu);

    RelLay = (RelativeLayout) findViewById (R.id.RelLay);
    AdView ad = (AdView) findViewById(R.id.ad);

    AdView adView = new AdView(this.getApplicationContext());

        adView = new AdView(this);
        adView.setAdSize(AdSize.SMART_BANNER);
        adView.setAdUnitId("ca-app-pub-5045823047142424/5834743995");
        RelLay.addView(adView, 0);
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);


    populateListView();
    registerClickCallBack();

}

我的 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/res-auto"
android:id="@+id/RelLay"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
 <ListView
    android:id="@+id/listView"
    android:layout_width="wrap_content"
    android:layout_height="400dp"
    android:layout_alignParentTop="true" >
</ListView>

<com.google.android.gms.ads.AdView
    android:id="@+id/ad"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentBottom="true"
    ads:adSize="SMART_BANNER"
    android:layout_below="@id/listView"
    ads:adUnitId="ca-app-pub-5045823047142424/5834743995" 
    android:layout_weight="1"/>
</RelativeLayout>

当它出现在活动的顶部时,我收到如下错误:

04-30 16:17:57.787:E/eglCodecCommon(1468):

**** 错误未知类型 0x0 (glSizeof,72)

glUtilsParamSize: 未知参数 0x00000b44

glUtilsParamSize: 未知参数 0x00000bd0

**** 错误未知类型 0x0 (glSizeof,72)

glUtilsParamSize: 未知参数 0x00000b44

glUtilsParamSize: 未知参数 0x00000bd0

**** 错误未知类型 0x0 (glSizeof,72)

【问题讨论】:

    标签: java android xml admob


    【解决方案1】:

    创建一个父垂直LinearLayout 并放置您的ListView,布局权重为2,AdView 权重为1。这将确保ListView 位于顶部并根据AdView 调整其高度。这样AdView 将始终显示在底部。

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">
    
    <ListView
        android:id="@+id/listView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@color/Red"
        android:layout_weight="2"/>
    
    <com.google.android.gms.ads.AdView
        android:id="@+id/welcomeAdView"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        ads:adSize="SMART_BANNER"
        ads:adUnitId=""
        android:layout_weight="1"/>
    </LinearLayout>
    

    另外,更改您的代码以仅加载广告,不要将 AdView agin 添加到布局中

       AdView ad = (AdView) findViewById(R.id.ad);
       AdRequest adRequest = new AdRequest.Builder().build();
       ad.loadAd(adRequest);
    

    【讨论】:

    • 当我这样做时,广告仍然显示在顶部:/
    • 不,它应该可以工作,确保 android:layout_height="wrap_content"
    • 如果需要,也可以尝试为 adview 设置一些高度
    • 我做了你说的所有事情,但它仍然显示在活动的顶部:/
    【解决方案2】:

    使用简单的xml横幅不需要java

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
            xmlns:tools="http://schemas.android.com/tools"
    
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
    
            <com.google.ads.AdView
                android:id="@+id/ad"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                ads:adSize="BANNER"
                ads:adUnitId="your publisher id here"
                ads:loadAdOnCreate="true" />
    
    
        </RelativeLayout>
    

    【讨论】:

    • 这行不通。他需要将横幅放在底部,其他视图放在顶部。
    【解决方案3】:

    您的代码很好,但您需要 ListView android:above="@+id/ad"

    【讨论】:

    • 执行此操作时我的应用程序崩溃了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-06
    • 2023-03-21
    • 1970-01-01
    • 2017-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多