有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java无法让admobs广告显示在底部

我在谷歌和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:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:ads="http://schemas.安卓.com/apk/res-auto"
安卓:id="@+id/RelLay"
安卓:layout_width="fill_parent"
安卓:layout_height="match_parent" >
 <ListView
    安卓:id="@+id/listView"
    安卓:layout_width="wrap_content"
    安卓:layout_height="400dp"
    安卓:layout_alignParentTop="true" >
</ListView>

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

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

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

**** ERROR unknown type 0x0 (glSizeof,72)

glUtilsParamSize: unknow param 0x00000b44

glUtilsParamSize: unknow param 0x00000bd0

**** ERROR unknown type 0x0 (glSizeof,72)

glUtilsParamSize: unknow param 0x00000b44

glUtilsParamSize: unknow param 0x00000bd0

**** ERROR unknown type 0x0 (glSizeof,72)


共 (2) 个答案

  1. # 1 楼答案

    你的代码很好,但你需要ListView android:over=“@+id/ad”

  2. # 2 楼答案

    创建一个父垂直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>
    

    另外,将代码更改为只加载广告,不要将AdViewagin添加到布局中

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