2016-04-20 6 views
0

基本的には、画面の半分をタブレイアウトにし、イメージの半分(または実際には他のもの)を使用します。それは私が体重を加え始めるまでうまく動作します。Androidの重み付けされたフラグメントが表示されない

そのまま、何も表示されません。この問題の原因は何ですか?量成分タブ関連のものを表示しなければ

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

が、私はそれが示されていないとして、それはイメージを押し出すと仮定しています。

ご協力いただければ幸いです。 :)

UPDATE:要求されたとして

ここではスクリーンショットです:Weighted

、呼び出しアクティビティ:

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

スクリーンショットを追加できますか? – AndiGeeky

+0

このフラグメントをどのように呼び出していますか。そのコードを追加してください。 –

答えて

0

FragmentTabHostlinkのドキュメントを見ると、それはLinearLayoutから継承されていないことがわかります。基本的にlayout_weightはこのコンテナでサポートされていません。これを正しく機能させるには、さらにLinearLayoutのトップを追加することをお勧めします。

<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

ありがとう!これは私のためにやった。私は理解していないより多くのアンドロイドのジャンクを介してスローガンに戻る。 – WDude

0

使用childFragmentManager代わりFragmentManager

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

ネイティブフラグメント内でネストされたフラグメントを使用する場合。 getFragmentManager()を使用してください。

サポートライブラリのフラグメント内でネストされたフラグメントを使用する場合は、getChildFragmentManager()を使用してください。

+0

「getChildFragmentManager()」を使用するには追加のインクルードが必要ですか? – WDude

+0

チェックhttp://stackoverflow.com/a/21064614/2826147とhttp://stackoverflow.com/a/17236958/2826147 –

+0

私はすでにそれを見てきました。これが私がこれまで主な理由です。 – WDude

関連する問題