2014-01-22 88 views
2

我试图把一个标签主机放在一个片段活动, 我做了一个自定义的布局来保存标签,并把该视图inttabner的setIndicator ,但不幸的是选项卡不是展示...... 任何人可以帮助...片段没有显示在片段活动

public class MainActivity extends FragmentActivity { 

    private FragmentTabHost mTabHost; 
    LayoutInflater inflater; 
    View tabdesign, tabSplitter; 
    AddFragment addfragment; 
    private ImageView label; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     this.requestWindowFeature(Window.FEATURE_NO_TITLE); 

     setContentView(R.layout.activity_main); 
     //check configuration 
     // Configuration config = getResources().getConfiguration(); 

     //setting up tabs 


      tabdesign = inflater.inflate(R.layout.inside_tab_design, null); 
      mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); 
      mTabHost.setup(this, getSupportFragmentManager(), R.id.content); 

      inflater = (LayoutInflater) getBaseContext().getSystemService(
        Context.LAYOUT_INFLATER_SERVICE); 
      label=(ImageView)tabdesign.findViewById(R.id.tablabel); 
      label.setImageResource(R.drawable.settings); 
      mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator(tabdesign), 
        SmallFragment.class, null); 
      tabSplitter = (View) tabdesign.findViewById(R.id.tabSplitter); 


      tabdesign = inflater.inflate(R.layout.inside_tab_design, null); 
      label = (ImageView) tabdesign.findViewById(R.id.tablabel); 
      label.setImageResource(R.drawable.settings); 
      mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator(tabdesign), 
        TabeFragment.class, null); 

    } 

} 

这是我主要的xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:background="@android:color/black"> 

    <FrameLayout 
     android:id="@+id/content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" >   
    </FrameLayout> 


    <android.support.v4.app.FragmentTabHost 
     android:id="@android:id/tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="52dp" > 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="0dp" 
      android:layout_height="0dp" 
      android:layout_weight="0" /> 
    </android.support.v4.app.FragmentTabHost> 

</LinearLayout> 

这是我的自定义标签布局视图:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tab" 
    android:layout_width="match_parent" 
    android:layout_height="52dp" 
    android:background="#898989" 
    android:orientation="vertical" > 



    <View 
     android:id="@+id/tabSplitter" 
     android:layout_width="1dip" 
     android:layout_height="match_parent" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:background="#ffffff" /> 

    <ImageView 
     android:id="@+id/tablabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     /> 

</RelativeLayout> 
+0

正如我所看到的,你只有他TabHost在你的XML,但不是一个单一的标签元素。您需要添加至少一个 Fraggles

回答

0

尝试了这一点:

<android.support.v4.app.FragmentTabHost 
    android:id="@android:id/tabhost" 
    android:layout_width="match_parent" 
    android:layout_height="52dp" > 

    <TabWidget android:id="@android:id/tabs" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent"/> 

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

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

我可以动态地将标签添加到它的权利... –

+0

它没有解决我的问题... –

+0

嗯...对不起,只是我的想法 – Fraggles