2011-11-23 260 views
0

我再次需要一些幫助。反覆試驗並不能很好地發揮作用。有人可以看看我的代碼嗎?我希望我的列表視圖在頁面頂部包含admob廣告,今天早上我有點掙扎。提前致謝!上載到列表視圖:Android佈局

<?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:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:padding="5dp" 
    > 

    <com.google.ads.AdView 
      android:id="@+id/adView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      ads:adSize="BANNER" 
      ads:adUnitId="xxxxxxxxxxxxxxx" 
      ads:loadAdOnCreate="true" 
      android:layout_alignParentTop="true" /> 

    <TextView 
     android:id="@+id/txtPlaceName" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="left" 
     android:ellipsize="end" 
     android:singleLine="true" 
     android:text="saa" 
     android:textSize="25sp" 
     android:layout_below="@id/adView" /> 

    <LinearLayout 
     android:id="@+id/layout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <ImageView 
      android:id="@+id/imgType" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/marker1" /> 

     <LinearLayout 

      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" > 

       <TextView 
        android:id="@+id/txtCityState" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="city, st" 
        android:textSize="15sp" /> 

       <TextView 
        android:id="@+id/txtDistance" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true" 
        android:textSize="15sp" /> 
      </RelativeLayout> 

      <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" > 

       <RatingBar 
        android:id="@+id/average_ratingbar" 
        style="?android:attr/ratingBarStyleSmall" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentLeft="true" 
        android:numStars="5" 
        android:stepSize="1.0" /> 

       <TextView 
        android:id="@+id/txtCommentsCount" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true" 
        android:textSize="15sp" /> 
      </RelativeLayout> 
     </LinearLayout> 
    </LinearLayout> 



</LinearLayout> 

回答

1

簡短的回答

橫幅廣告需要320dp寬度。您的基礎LinearLayout有android:padding="5dp",因此您只剩下310dp,因此廣告不適合屏幕顯示。

對於未來

Android有所謂LogCat日誌記錄工具,跟蹤所記錄的所有消息。 AdMob SDK提供的日誌消息在調試這些問題時非常有用。這是我能夠解決你的問題。

您可以按照上面提供的鏈接指示使用命令行查看LogCat輸出,也可以通過訪問Window -> Show View -> LogCat來查看Eclipse中的LogCat輸出。當請求廣告的SDK記錄以下消息:

Not enough space to show the ad! Wants: <320,50>, Has: <310,473> 

從那裏,它是很容易告訴你沒有完整的320寬度,足以確保您的頂層佈局有5DP填充每個側。

無關佈局提示

僅供參考,android:layout_alignParentTopandroid:layout_below屬性只能做任何事情的RelativeLayout內。在上面提供的佈局中,AdView和TextView上的這些屬性不起任何作用。