2012-01-08 57 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>