Я очень новичок в Android (например, 2 дня), но у меня есть опыт работы с другими инструментами компоновки. Я пытаюсь поместить AdView под TabHost, и кажется, что я могу заставить TabWidget или AdView отображаться правильно, но никогда оба.
Во-первых, вот художественная версия ASCII того, что я пытаюсь выполнить:
-------------------------------------------- | Tab 1 | Tab 2 | -------------------------------------------- | MapView when tab 1 is selected | | | | | | | | | | | | | -------------------------------------------- | AdView that stays no matter what tab | --------------------------------------------
Как видите, я пытаюсь вывести AdView вне TabWidget или FrameLayout. Я хочу, чтобы он был ниже всего содержимого вкладки.
Вот макет, который у меня получился до добавления 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>
Теперь я попробовал несколько разных советов, чтобы добавить AdView, например http://www.spencerelliott.ca/blogs/blog-android-menu. Вот лучший макет, который я придумал:
<?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>
К сожалению, в этом случае мой MapView на первой вкладке помещает элементы управления масштабированием поверх AdView. Есть ли какой-то простой макет, который мне не хватает? Потому что я могу настроить TabWidget на wrap_content для высоты или AdView на wrap_content для высоты, но только когда они выходят за пределы «@android:id/tabcontent».
Все, что ниже содержимого вкладки, съедается MapView.
Спасибо