2016-04-20 13 views
0

Grundsätzlich, was ich versuche zu tun ist, haben die Hälfte des Bildschirms ein Tab-Layout und ein halbes Bild (oder wirklich alles andere). Es funktioniert gut, bis ich anfange, Gewicht hinzuzufügen.Android gewichtet Fragment nicht angezeigt

Es wird nichts angezeigt. Was würde dieses Problem verursachen?

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

Ohne die Gewichtskomponente wird die Tab-bezogene Sachen angezeigt, aber ich nehme an, es schiebt das Bild aus, wie es nicht gezeigt wird.

Jede Hilfe wäre willkommen. :)

UPDATE:

Hier ist ein Screenshot wie gewünscht: Weighted

Und die anrufende Aktivität:

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

Können Sie einen Screenshot hinzufügen? – AndiGeeky

+0

wie Sie dieses Fragment aufrufen. füge bitte diesen Code hinzu. –

Antwort

0

Wenn man sich die Dokumentation aussehen auf FragmentTabHostlink, werden Sie sehen, dass es nicht von LinearLayout geerbt hat, so dass im Grunde layout_weight wird von diesem Behälter unterstützt. Ich würde vorschlagen, zusätzliche LinearLayout hinzufügen, damit dies richtig funktioniert.

<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

Danke! Das hat es für mich getan. Zurück zu Slogging durch mehr Android-Müll verstehe ich nicht. – WDude

0

Verwendung childFragmentManager statt FragmentManager

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

Wenn Sie verschachtelte Fragmente innerhalb eines nativen Fragments verwenden möchten. Verwenden Sie getFragmentManager().

Wenn Sie verschachtelte Fragmente innerhalb einer Support-Bibliothek Fragment verwenden möchten, verwenden Sie getChildFragmentManager().

+0

brauche ich ein zusätzliches Include, um 'getChildFragmentManager()' zu verwenden? – WDude

+0

überprüfen http://Stackoverflow.com/a/21064614/2826147 und http://Stackoverflow.com/a/17236958/2826147 –

+0

Ich habe schon angeschaut. Das ist der Hauptgrund, warum ich so weit bin. – WDude