AdView会在几秒钟后显示,但它是透明的,listView占据整个屏幕。到处看,但无法让Adview表现出来。你能看到我做错了什么,以便ListView为Adview腾出空间吗?
@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>
答案 0 :(得分: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>
答案 1 :(得分:0)
您正在使用相对布局,并且您声明的最后一个视图将被绘制在其他视图之上。如果您想将广告放在列表视图上方,则必须在xml文件中的LinearLayout下面声明AdView小部件