簡體   English   中英

如何使用包含MapView的TabHost,它還在其下方顯示AdMob視圖?

[英]How can I use a wrap a TabHost containing a MapView that also displays an AdMob view below it?

我是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>

現在,我嘗試了幾個不同的提示來添加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將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>

在上半部分之前聲明視圖的下半部分有點違反直覺:-)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM