I am very new to Android (e.g. 2 days), but I have experience with other layout tools. I am trying to put AdView under TabHost, and it seems that I can either make TabWidget or AdView display correctly, but never both.
Firstly, here is the ASCII art version of what I'm trying to accomplish:
--------------------------------------------
| Tab 1 | Tab 2 |
--------------------------------------------
| MapView when tab 1 is selected |
| |
| |
| |
| |
| |
| |
--------------------------------------------
| AdView that stays no matter what tab |
--------------------------------------------
As you can see, I'm trying to get an AdView outside of TabWidget or FrameLayout. I want it to be below the entire contents of the shepherd.
Here is the layout I have before adding AdView:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:myapp="http://schemas.android.com/apk/res/org.mbs3.android.ufcm" android:layout_height="fill_parent" android:layout_width="wrap_content" > <TabHost android:id="@+id/tabhost" android:layout_width="fill_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="fill_parent" android:id="@+id/home_layout" android:orientation="vertical" android:layout_height="fill_parent"> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent"> <RelativeLayout android:id="@+id/emptylayout1" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </FrameLayout> </LinearLayout> </TabHost> </RelativeLayout>
Now I have tried a couple of different tips to add AdView, for example http://www.spencerelliott.ca/blogs/blog-android-menu . Here is the best layout I came up with:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:myapp="http://schemas.android.com/apk/res/org.mbs3.android.ufcm" android:layout_height="fill_parent" android:layout_width="wrap_content"> <TabHost android:id="@+id/tabhost" android:layout_width="fill_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="fill_parent" android:id="@+id/home_layout" android:orientation="vertical" android:layout_height="fill_parent"> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent"> <RelativeLayout android:id="@+id/emptylayout1" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </FrameLayout> </LinearLayout> </TabHost> <LinearLayout android:layout_width="fill_parent" android:id="@+id/ad_layout" android:layout_height="wrap_content" android:gravity="bottom" android:layout_alignParentBottom="true" android:layout_alignBottom="@+id/home_layout"> <com.admob.android.ads.AdView android:id="@+id/ad" android:layout_width="fill_parent" android:layout_height="wrap_content" myapp:backgroundColor="#000000" myapp:primaryTextColor="#FFFFFF" myapp:secondaryTextColor="#CCCCCC" myapp:keywords="words" /> </LinearLayout> </RelativeLayout>
Unfortunately, in this case, my MapView on the first tab places Zoom controls on top of AdView. Is there some simple layout that I am missing? Because I can get TabWidget for wrap_content for height or AdView for wrap_content for height, but only when they go above "@android: id / tabcontent."
Everything below the contents of the tab is eaten by MapView.
thanks
android android-tabhost google-maps admob android-mapview
Martin
source share