How can I use a TabHost wrapper containing a MapView that also displays an AdMob view above it?

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" /> <!-- programatically added tabs will appear here, one per activity --> </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" /> <!-- programatically added tabs will appear here, usually one per activity --> </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

+6
android android-tabhost google-maps admob android-mapview
source share
1 answer

Not sure if this is the same thing, but I had to put a button at the bottom of the action and fill the rest of the ListView space. For this, I did something like this:

 <RelativeLayout> <LinearLayout android:id="@+id/ad_id" android:layout_alignParentBottom="true" android:layout_height="wrap_content" android:layout_width="fill_parent"> <!-- the ad goes here --> </LinearLayout> <TabHost android:layout_above="@id/ad_id" android:layout_height="fill_parent" android:layout_width="fill_parent"> <!-- your view --> </TabHost> </RelativeLayout> 

A bit counter-intuitive to declare the bottom of the view in front of the top :-)

+5
source share

All Articles