0

ListActivity に対応する次の XML ファイルがあります。

<?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.ads"
    android:id="@+id/classview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="xxxx" >
    </com.google.ads.AdView>

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>

そして、ListActivity 内からこの Java コードを呼び出します。

public void setupAd(){
    AdRequest adRequest = new AdRequest();
    adRequest.addTestDevice("xxxx");
    AdView adView = (AdView) findViewById(R.id.adView);
    adView.loadAd(adRequest);


}

XML ファイルのグラフィカル レイアウトを見ると、ListView の上に広告バナーがきちんと配置されているように見えます。ただし、実際のアプリを実行すると、ListView が画面全体を占有しているように見え、広告がブロックされる可能性があります。誰が何が悪いのか知っていますか?

4

1 に答える 1

0

問題は、ListView に layout_height="fill_parent" があることです。

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
 />

代わりに、wrap_content を使用し、layout_weight="1" を使用して、未使用のスペースを消費するように指示します。

于 2013-08-28T01:21:52.993 に答える