Reputation: 577
I am trying to display an adMob Ad Banner a the top of the screen. However, as seen below, it is displaying in the middle. Anyone know how I can fix this?
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
ndroid:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="@drawable/main_bg" >
<LinearLayout
android:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:paddingTop="30dip"
android:layout_height="wrap_content"
android:gravity="center" >
<ImageButton
android:id="@+id/mnwvbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dip"
android:background="@drawable/mnwvicon" />
<ImageButton
android:id="@+id/reportsbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/reportsicon" />
</LinearLayout>
<ImageButton
android:id="@+id/mnwvshowbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/showicon"
android:paddingTop="30dip" />
</LinearLayout>
This is where I add the AdView the my LinearLayout in my code:
// Admob Banner ***********
layout = (LinearLayout)findViewById(R.id.linearLayout);
adView = new AdView(this, AdSize.BANNER, "a14ed285a63276d");
layout.addView(adView);
adView.loadAd(new AdRequest());
// *************************
Here is what appears on my screen:
Upvotes: 0
Views: 1343
Reputation: 425
I suggest you to use relativ layout. In the following layout, based on yours, the ad layout has for id "adLayout":
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
ndroid:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/main_bg" >
<LinearLayout
android:id="@+id/adLayout"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<LinearLayout
android:layout_below="@id/adLayout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:paddingTop="30dip"
android:layout_height="wrap_content">
[...]
Upvotes: 1
Reputation: 926
The linearLayout you're adding to is the parent element; the whole screen. Try adding a child linear layout to it (another linear layout completely contained within the main one) and set android:gravity="bottom".
Here's an example without the buttons.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/main_bg" >
<LinearLayout
android:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom" >
</LinearLayout>
Or relative parent (The styles include just basic sizing. Parent fills screen, child wraps ad.):
<RelativeLayout
style="@style/FPFP">
<LinearLayout
android:id="@+id/ads"
style="@style/WCWC"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
Upvotes: 1