0

我正在尝试将 Admob 集成到我的 TableLayout 中。不幸的是,它从未在屏幕上显示。布局仅包含顶部的一些文本字段和一个地图视图,广告视图应放置在底部。我的 XML 布局如下所示:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1" 
android:id="@+id/main">

<TableRow>

    <TextView
        android:id="@+id/txt1"
        android:gravity="center"
        android:text="text1"
        android:textSize="25sp" 
        android:layout_span="3"/>
</TableRow>


<TableRow>
    <TextView
    android:id="@+id/txt2"
    android:gravity="center"
    android:text="txt2"
    android:textSize="25sp"
    android:layout_span="3"
    />

</TableRow>

<TableRow>

    <TextView
        android:id="@+id/txt3"
        android:gravity="left"
        android:text="txt3"
        android:textSize="25sp" 
        android:paddingLeft="20sp"/>

    <TextView
        android:id="@+id/txt4"            
        android:gravity="right"
        android:text="txt4"
        android:textSize="25sp"
        android:paddingRight="20sp"/>
</TableRow>

<TableRow>
<com.google.android.maps.MapView
    android:layout_span="2"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:apiKey="XXX"
    android:clickable="true"
    />
 </TableRow>

<TableRow>

<com.google.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="XXX"
                     ads:adSize="BANNER"
                     ads:testDevices="TEST_EMULATOR, XXX"
                     ads:loadAdOnCreate="true"
                     android:layout_span="2"
                     />  
</TableRow>
</TableLayout>

有人可以告诉我为了让 Adview 正确显示我必须改变什么吗?

4

1 回答 1

1

Try this way, as I create simple demo for your understand...!?! I think it helps you

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:shrinkColumns="*"
android:stretchColumns="*" >

<TableRow
    android:id="@+id/tableRow0"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0"
    android:background="@drawable/info_headstriplogo"
    android:gravity="top" >

    <ImageButton
        android:id="@+id/ibGMapLocationBack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left|bottom"
        android:layout_margin="5dp"
        android:layout_span="2"
        android:background="@null"
        android:contentDescription="@id/ibGMapLocationBack"
        android:src="@drawable/back" />
</TableRow>

<TableRow
    android:id="@+id/tableRow1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" >

    <com.google.android.maps.MapView
        android:id="@+id/mapView"
        android:layout_span="2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:apiKey="0zzbEqGyRIg8wikQPkcwDvqhM6x0TwcSHozLlZg"
        android:clickable="true"
        android:enabled="true" />
</TableRow>

<TableRow
    android:id="@+id/tableRow10"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="0"
    android:background="@drawable/footerstrip"
    android:gravity="bottom" >
</TableRow>

于 2012-09-08T07:33:12.970 回答