我有列表视图,我想在此列表视图的底部显示广告横幅,我也为此横幅创建了空间,即android:paddingBottom =“50dp”,所以我想在这个50dp空间展示广告但是现在我的广告显示在这个50dp空间的上面我有1个MainActivity.java和2个xml文件,第一个是activity_main.xml,第二个是single_row.xml。我们知道没有必要显示java类,因为我们通过xml设置广告调整。所以我在这里分享我的两个xmls并记住我的相对布局不是线性的,因此没有layout_weight选项。 activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg"
android:paddingBottom="50dp"
tools:context=".MainActivity" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
<LinearLayout
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" >
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
ads:adSize="BANNER"
ads:adUnitId="aaaa111122223333"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" >
</com.google.ads.AdView>
</LinearLayout>
</RelativeLayout>
我的sigle_row.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" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_margin="10dp"
android:src="@drawable/img0"
android:paddingBottom="10dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/imageView1"
android:layout_toLeftOf="@+id/imageView1"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFF00"
android:textStyle="bold"
/>
</RelativeLayout>
答案 0 :(得分:2)
您需要将layout_above
的{{1}}设置为放置在ListView
布局上方,以便您可以看到所有列表项
AdView
另外,从父 android:layout_above="@+id/layout"
padding
答案 1 :(得分:1)
android:paddingBottom
用于在View
内的底部留出一些空格,而不是为其他Views
指定一些空格。
现在,从父RelativeLayout
android:paddingBottom="50dp"
并将50dp
设置为android:layout_height
的{{1}}属性,如下所示
com.google.ads.AdView
答案 2 :(得分:0)
使用一个相对的容器,在其中使用layout_above="@id/your_adview_id"
上的listview
。
在adView
下添加ListView
并设置其visibility="gone"
。
在您的Java中,加载加载项时,将可见性设置为adView.setVisibility(View.VISIBLE);
可见
我希望这会有所帮助:)