android - 我如何使用包含 MapView 并在其下方显示 AdMob View 的 TabHost 包装?

标签 android google-maps android-mapview android-tabhost admob

我是 Android 的新手(大约 2 天),但我对其他布局工具包很熟悉。我试图将 AdView 放在 TabHost 下方,似乎我可以让 TabWidget 或 AdView 正确显示,但不能同时显示。

首先,这是我要完成的 ASCII 艺术版本:

--------------------------------------------
| 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 the AdView outside the TabWidget or FrameLayout. I want it to be below the whole tabhost contents.

Here's the layout I've got before adding the 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 吃掉。

谢谢

最佳答案

不确定是否是同一件事,但我不得不在 Activity 的底部放置一个按钮,并用 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>

在上半部分之前声明 View 的下半部分有点违反直觉:-)

关于android - 我如何使用包含 MapView 并在其下方显示 AdMob View 的 TabHost 包装?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3741921/

相关文章:

javascript - 在 apache cordova 中获取 "google not defined"

ios - 在 iOS 中的 Google map 上绘制 GMSPolyline

java - android.view.InflateException : Binary XML file line #6: Error inflating class com. google.android.gms.maps.MapView

android - Mapview Fragment + ViewPager,导致奇怪的交互

android - 如何更改android年月中的日期格式

android - 如何从选定的 mp3 文件中提取信息?

android - webview android 中的 Paypal 支付页面布局损坏

android - 如何在 Android 操作系统上托管 Web 应用程序

Android Google MapView 仅显示空图 block

java - 如何更改 Android 中 map View 上可绘制对象的大小?