Mar*_*tin 6 android google-maps admob android-tabhost android-mapview
我是Android的新手(比如2天),但我对其他布局工具包很有经验.我正试图将一个AdView放在TabHost下面,似乎我可以让TabWidget或AdView正确显示,但绝不会同时显示.
首先,这是我想要完成的ASCII艺术版本:
-------------------------------------------- | Tab 1 | Tab 2 | -------------------------------------------- | MapView when tab 1 is selected | | | | | | | | | | | | | -------------------------------------------- | AdView that stays no matter what tab | --------------------------------------------
正如您所看到的,我正在尝试在TabWidget或FrameLayout 之外获取AdView .我希望它低于整个tabhost内容.
这是我在添加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>
Run Code Online (Sandbox Code Playgroud)
现在,我尝试了几个不同的技巧来添加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>
Run Code Online (Sandbox Code Playgroud)
不幸的是,在那个中,我在第一个选项卡中的MapView将Zoom控件放在AdView的顶部.我缺少一些简单的布局吗?因为我可以将TabWidget设置为wrap_content的高度,或者将AdView设置为wrap_content的高度,但只有当它们超过"@android:id/tabcontent"时才能获得.
选项卡内容下面的任何内容都会被MapView吃掉.
谢谢
不确定它是否是相同的东西,但我必须在活动的底部放置一个Button,并用ListView填充剩余的空间.要做到这一点,我做了一些像这样的事情:
<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>
Run Code Online (Sandbox Code Playgroud)
在上半部分之前声明视图的下半部分有点违反直觉:-)