2011-11-23 97 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上的这些属性不起任何作用。