我在屏幕底部添加广告,但广告距离底部大约10dp,这给人一种奇怪的外观。我检查了所有相关问题但我无法找到答案。这是我的代码
<com.google.ads.AdView android:id="@+id/admobAd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="***********"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"
android:layout_alignParentBottom="true"
android:layout_weight="1"
/>
提前致谢。
更新
这是我的完整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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ton"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".StartingPoint" >
<TextView
android:id="@+id/Test1"
android:layout_width="62dp"
android:layout_height="45dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:background="@drawable/rounded_corner"
android:gravity="center"
android:text="Test"
android:textColor="@color/black"
android:textSize="20dp" />
<TextView
android:id="@+id/Test2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="53dp"
android:textSize="12dp" >
</TextView>
<com.google.ads.AdView
android:id="@+id/adView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="1"
ads:adSize="BANNER"
ads:adUnitId="******"
ads:loadAdOnCreate="true"
android:gravity="bottom"
/>
</RelativeLayout>
答案 0 :(得分:1)
我已经使用此修改了你的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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ton"
android:orientation="vertical"
tools:context=".StartingPoint" >
<TextView
android:id="@+id/Test1"
android:layout_width="62dp"
android:layout_height="45dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:background="@drawable/rounded_corner"
android:gravity="center"
android:text="Test"
android:textColor="@color/black"
android:textSize="20dp" />
<TextView
android:id="@+id/Test2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="53dp"
android:textSize="12dp" >
</TextView>
<com.google.ads.AdView
android:id="@+id/adView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="1"
ads:adSize="BANNER"
ads:adUnitId="******"
ads:loadAdOnCreate="true"
android:gravity="bottom"
/>
</RelativeLayout>
我从你的相对布局中删除了android:paddingBottom =“@ dimen / activity_vertical_margin”..这个
答案 1 :(得分:0)
您可以动态地将Admob横幅的位置设置到屏幕底部。请参考下面的代码,这可能会对您有所帮助 -
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
RelativeLayout relativeLayout = new RelativeLayout(this);
mFrameLayout.addView(relativeLayout);
RelativeLayout.LayoutParams adViewParams = new RelativeLayout.LayoutParams(
AdView.LayoutParams.WRAP_CONTENT,
AdView.LayoutParams.WRAP_CONTENT);
// align bottom
adViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
// align center
adViewParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
relativeLayout.addView(adView, adViewParams);
adView.loadAd(adRequest);
adView.setBackgroundColor(Color.BLACK);
adView.setBackgroundColor(0);
干杯:)