【问题标题】:How to make swipe tabs layout inside a fragment of a navigation drawer?如何在导航抽屉的片段内制作滑动标签布局?
【发布时间】:2016-07-19 15:10:59
【问题描述】:

我正在按照官方的 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 布局?

【问题讨论】:

  • 取决于“设置”方法。发布该方法的代码并解释究竟是什么不起作用。
  • 好吧..一个有效的 XML 布局?

标签: android android-studio tabs fragment navigation-drawer


【解决方案1】:

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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多