2012-01-08 58 views
0

我试图将Admob集成到我的TableLayout中。不幸的是,它从未在屏幕上显示。该布局仅包含顶部的一些文本框和一个地图视图,广告视图应放置在底部。我的XML布局看起来是这样的:将Admob Adview集成到TableLayout/TableRow中

<?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的改变正确显示?

+0

总结一些布局内的AD浏览?可能相对布局和尝试。这里是从其他SO讨论(我知道这个链接是为TabHost不是TableLayout,但概念是相同的)参考链接http://stackoverflow.com/questions/3576117/android-tabview-layout-with-admob – kosa 2012-01-08 16:25:12

+0

我已经试过了像这样,但这也没有工作:( – nr1 2012-01-08 16:35:30

+0

你看到日志logcat说,饲料收到?如果是这样,它主要是与您的布局设置,玩高和宽度等, – kosa 2012-01-08 16:36:33

回答

1

尝试这种方式,因为我为你的理解创建简单的演示...!?! 我认为它可以帮助你

<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>