2010-09-18 10 views
6

Jestem bardzo nowy na Androida (jak 2 dni), ale mam doświadczenie z innymi zestawami narzędzi do tworzenia layoutów. Próbuję umieścić AdView poniżej TabHost i wydaje mi się, że mogę ustawić wyświetlanie TabWidget lub AdView poprawnie, ale nigdy oba.Jak używać zawijania TabHost zawierającego MapView, który wyświetla poniżej widok AdMob?

pierwsze, oto ASCII wersja sztuki, co usiłuję osiągnąć:

 
-------------------------------------------- 
| Tab 1    | Tab 2    | 
-------------------------------------------- 
| MapView when tab 1 is selected   | 
|           | 
|           | 
|           | 
|           | 
|           | 
|           | 
-------------------------------------------- 
| AdView that stays no matter what tab  | 
-------------------------------------------- 

Jak widać, próbuję uzyskać adview poza TabWidget lub FrameLayout. Chcę, żeby znajdował się pod całą zawartością tabhost.

Oto układ Mam przed dodanie 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> 

Teraz próbowałem kilka różnych wskazówek, aby uzyskać adview dodał, takie jak http://www.spencerelliott.ca/blogs/blog-android-menu. Oto najlepszy układ wymyśliłem:

<?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> 

Niestety, w tym jeden, mój MapView w pierwszej zakładce stawia Zoom kontroluje na górze adview. Czy brakuje jakiegoś prostego układu? Ponieważ mogę dostać TabWidget do wrap_content na wysokość lub AdView do wrap_content na wysokość, ale tylko wtedy, gdy przekroczą "@android: id/tabcontent".

Wszystko poniżej zawartości karty zostanie zjedzone przez MapView.

Dzięki

Odpowiedz

5

Nie wiem, czy to jest to samo, ale musiałem umieścić przycisk na dole działalności i wypełnić resztę przestrzeni z ListView. Aby to zrobić, zrobiłem coś nieco więcej tak:

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

Jest to sprzeczne z intuicją nieco zadeklarować dolną część widoku przed górnej części :-)

Powiązane problemy