2013-10-24 25 views
0

AdView在几秒钟后显示,但它是透明的,listView占用整个屏幕。无处不在,但无法让Adview行事。你能看到我做错了什么,所以ListView为Adview腾出空间吗?Admob在ListActivity中透明

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    this.setContentView(R.layout.activity_with_adview); 
} 

activity_with_adview.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <com.google.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:layout_alignParentBottom="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="xxxxxxxxxxxxxx" 
     ads:loadAdOnCreate="true" 
     ads:testDevices="TEST_EMULATOR" 
     android:background="@android:color/black" /> 

    <LinearLayout 
     android:id="@+id/home_layout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@id/adView" 
     android:orientation="vertical" > 

     <ListView 
      android:id="@id/android:list" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@android:color/black" > 
     </ListView> 

    </LinearLayout> 

</RelativeLayout> 

example of problem

回答

0

我是铺设在上面的列表片段。认为片段是一个列表。

@Override 
protected void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 

    this.setContentView(R.layout.activity_with_adview); 

    if (TradiesBillingManager.hasPurchasedDiary()) { 

     if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) { 
      DiaryFragment list = new DiaryFragment(); 
      list.setArguments(getIntent().getExtras()); 
      getSupportFragmentManager().beginTransaction().add(android.R.id.content, list).commit(); 
     } 

    } else { 

     DiaryFragment list = new DiaryFragment(); 
     list.setArguments(getIntent().getExtras()); 
     getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout, list).commit(); 
    } 

} 

activity_with_adview.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <com.google.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:layout_alignParentTop="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="xxxxxxxxxxxxxx" 
     ads:testDevices="TEST_EMULATOR" 
     ads:loadAdOnCreate="true" 
     android:background="@android:color/black" /> 

    <FrameLayout 
     android:id="@+id/frame_layout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/adView" 
     android:orientation="vertical" /> 

</RelativeLayout> 
0

您正在使用你声明的最后一个相对布局和视图将在其他视图顶部画。如果您想将广告放在列表视图上方,则必须在xml文件中的LinearLayout下方声明AdView小部件