2016-07-19 57 views
0

我正在關注官方android教程,在我的導航抽屜的片段中插入滑動選項卡布局。如何在導航抽屜的片段內製作滑動標籤佈局?

import com.example.android.supportv4. 
    import android.os.Bundle; 
    import android.support.v4.app.FragmentActivity; 
    import android.support.v4.app.FragmentTabHost; 

/** 
* This demonstrates how you can implement switching between the tabs of a 
* TabHost through fragments, using FragmentTabHost. 
*/ 
public class FragmentTabs extends FragmentActivity { 
private FragmentTabHost mTabHost; 

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

    setContentView(R.layout.fragment_tabs); 
    mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost); 
    mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); 

    mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"), 
      FragmentStackSupport.CountingFragment.class, null); 
    mTabHost.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"), 
      LoaderCursorSupport.CursorLoaderListFragment.class, null); 
    mTabHost.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"), 
      LoaderCustomSupport.AppListFragment.class, null); 
    mTabHost.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"), 
      LoaderThrottleSupport.ThrottledLoaderListFragment.class, null); 
    } 
} 

請幫助我瞭解什麼是 「R.id.realtabcontent」。 如何製作此片段的XML佈局?

+0

取決於方法「設置」。發佈該方法的代碼,並解釋什麼是行不通的。 – Vucko

+0

well..a工作的XML佈局? –

回答

0

R.id.realtabcontent是FragmentTabHost的ID。下面是「fragment_tabs.xml」一個簡單的使用XML

<android.support.v4.app.FragmentTabHost 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/realtabcontent" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 
    <TabWidget 
    android:id="@android:id/tabs" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 
    <FrameLayout 
    android:id="@android:id/tab_content" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
    </FrameLayout> 
</LinearLayout></android.support.v4.app.FragmentTabHost>