6

Je suis très nouveau sur Android (comme 2 jours), mais je suis expérimenté avec d'autres kits d'outils de mise en page. J'essaie de placer un AdView sous un TabHost, et il me semble que je peux soit afficher le TabWidget ou l'AdView correctement, mais jamais les deux.Comment puis-je utiliser un onglet TabHost contenant un MapView qui affiche également une vue AdMob en dessous?

D'abord, voici une version ASCII art de ce que je suis en train d'accomplir:

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

Comme vous pouvez le voir, je suis en train d'obtenir le AdView en dehors la TabWidget ou FrameLayout. Je veux qu'il soit en dessous de tout le contenu du tabby.

est ici la mise en page que j'ai avant d'ajouter la 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> 

Maintenant, j'ai essayé quelques différents conseils pour obtenir le AdView ajouté, comme http://www.spencerelliott.ca/blogs/blog-android-menu. Voici la meilleure mise en page je suis venu avec:

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

Malheureusement, en ce sens, mon MapView dans le premier onglet met le zoom contrôle sur le dessus du AdView. Y a-t-il une mise en page simple qui me manque? Parce que je peux obtenir le TabWidget à wrap_content pour la hauteur, ou l'AdView à wrap_content pour la hauteur, mais seulement quand ils vont au-dessus du "@android: id/tabcontent."

Tout ce qui se trouve sous le contenu de l'onglet est mangé par MapView.

Merci

Répondre

5

Je ne sais pas si elle est la même chose, mais je devais mettre un bouton sur le fond d'une activité et remplir le reste de l'espace avec un ListView. Pour ce faire, je l'ai fait quelque chose d'un peu comme ceci:

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

Il est un peu contre-intuitif de déclarer la partie inférieure de la vue avant de la partie supérieure :-)

Questions connexes