Reputation: 143
I am adding ad at bottom of screen but ad is about 10dp above from bottom which gives really weird look. I have checked all related questions but I couldn't find answer. Here is my code
<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"
/>
Thanks in advance.
Update
Here is my complete 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>
Upvotes: 0
Views: 764
Reputation: 447
I Have modified your xml try using this.
<?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>
I Have removed android:paddingBottom="@dimen/activity_vertical_margin" from your relative layout ..try this out
Upvotes: 1
Reputation: 820
You can dynamically set the position of your Admob banner to the bottom of the screen. Refer below code, may be this might help you -
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);
Cheers :)
Upvotes: 0