2016-04-20 1 views
0

Fondamentalement, ce que j'essaie de faire est d'avoir la moitié de l'écran soit une disposition de tabulation et une demi-image (ou vraiment toute autre chose). Cela fonctionne très bien jusqu'à ce que je commence à ajouter du poids.Fragment pondéré Android ne montrant pas

En l'état, rien n'est affiché. Qu'est-ce qui causerait ce problème?

<android.support.v4.app.FragmentTabHost 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:gravity="left" 
    android:weightSum="2" 
    android:background="#00025a"> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:layout_weight="1"> 
     <TabWidget 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@android:id/tabs"> 
     </TabWidget> 

     <FrameLayout 
      android:layout_width="0dp" 
      android:layout_height="0dp" 
      android:id="@android:id/tabcontent"> 
     </FrameLayout> 

     <FrameLayout 
      android:id="@+id/tabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
     </FrameLayout> 
    </LinearLayout> 

    <ImageView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/test_room_1"/> 

</android.support.v4.app.FragmentTabHost> 

Sans le poids du composant l'onglet affiche des trucs liés, mais je suppose qu'il pousse l'image comme il ne figure pas.

Toute aide serait appréciée. :)

MISE À JOUR:

Voici une capture d'écran comme demandé: Weighted

Et l'activité d'appel:

import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import android.support.v4.app.FragmentTabHost; 
import android.widget.ImageView; 

public class sandbox_mode extends FragmentActivity { 
    ImageView level_background; 

    private FragmentTabHost mTabHost; 

    @Override 
    public void onCreate(Bundle savedInstanceState){ 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_sandbox_mode_play); 

     mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); 
     mTabHost.setup(this, getSupportFragmentManager(), R.id.tabcontent); 

     mTabHost.addTab(mTabHost.newTabSpec("Enemy Tab").setIndicator("Enemies"), 
       enemy_tab.class, null); 
    } 
} 
+0

Pouvez-vous ajouter une capture d'écran? – AndiGeeky

+0

comment vous appelez ce fragment. veuillez ajouter ce code. –

Répondre

0

Si vous regardez la documentation sur FragmentTabHostlink, vous verrez que ce n'est pas hérité de LinearLayout, donc en gros layout_weight n'est pas pris en charge par ce conteneur. Je suggère d'ajouter LinearLayout supplémentaire pour que cela fonctionne correctement.

<android.support.v4.app.FragmentTabHost 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" 
android:gravity="left" 
android:weightSum="2" 
android:background="#00025a"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:weightSum="2" /> 

    <LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:layout_weight="1"> 
    <TabWidget 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@android:id/tabs"> 
    </TabWidget> 

    <FrameLayout 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:id="@android:id/tabcontent"> 
    </FrameLayout> 

    <FrameLayout 
     android:id="@+id/tabcontent" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
    </FrameLayout> 
    </LinearLayout> 

    <ImageView 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:src="@drawable/test_room_1"/> 
</LinearLayout> 

</android.support.v4.app.FragmentTabHost> 
+0

Merci! Cela l'a fait pour moi. Retour à la tricherie à travers plus d'ordure Android je ne comprends pas. – WDude

0

utilisation childFragmentManager à la place FragmentManager

mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.tabcontent); 

Si vous souhaitez utiliser des fragments imbriqués dans un fragment natif . utilisez getFragmentManager().

Si vous souhaitez utiliser des fragments imbriqués dans une bibliothèque de support Fragment, utilisez getChildFragmentManager().

+0

Ai-je besoin d'un ajout supplémentaire pour utiliser 'getChildFragmentManager()'? – WDude

+0

vérifier http://stackoverflow.com/a/21064614/2826147 et http://stackoverflow.com/a/17236958/2826147 –

+0

J'ai déjà regardé cela. C'est la principale raison pour laquelle je suis si loin. – WDude