0

AdView 会在几秒钟后显示,但它是透明的,并且 listView 占据了整个屏幕。到处找,但无法让 Adview 正常工作。你能看到我做错了什么,所以 ListView 正在为 Adview 腾出空间吗?

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.activity_with_adview);
}

activity_with_adview.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="xxxxxxxxxxxxxx"
        ads:loadAdOnCreate="true"
        ads:testDevices="TEST_EMULATOR"
        android:background="@android:color/black" />

    <LinearLayout
        android:id="@+id/home_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/adView"
        android:orientation="vertical" >

        <ListView
            android:id="@id/android:list"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/black" >
        </ListView>

    </LinearLayout>

</RelativeLayout>

问题示例

4

2 回答 2

0

您正在使用相对布局,并且您声明最后一个视图将绘制在其他视图之上。如果要将广告放在列表视图上方,则必须在 xml 文件中的 LinearLayout 下方声明 AdView 小部件

于 2014-02-13T20:06:04.677 回答
0

我在顶部放置了一个列表片段。认为片段是一个列表。

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    this.setContentView(R.layout.activity_with_adview);

    if (TradiesBillingManager.hasPurchasedDiary()) {

        if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
            DiaryFragment list = new DiaryFragment();
            list.setArguments(getIntent().getExtras());
            getSupportFragmentManager().beginTransaction().add(android.R.id.content, list).commit();
        }

    } else {

        DiaryFragment list = new DiaryFragment();
        list.setArguments(getIntent().getExtras());
        getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout, list).commit();
    }

}

activity_with_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.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_alignParentTop="true"
        ads:adSize="BANNER"
        ads:adUnitId="xxxxxxxxxxxxxx"
        ads:testDevices="TEST_EMULATOR"
        ads:loadAdOnCreate="true"
        android:background="@android:color/black" />

    <FrameLayout
        android:id="@+id/frame_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/adView"
        android:orientation="vertical" />

</RelativeLayout> 
于 2013-10-24T05:27:20.800 回答