Android 如何在没有视图寻呼机的情况下创建选项卡

Android 如何在没有视图寻呼机的情况下创建选项卡,android,android-appcompat,Android,Android Appcompat,我需要三个选项卡,基本上改变了下面列表视图的排序。我不需要查看寻呼机或任何太复杂的东西,但我只能找到带有查看寻呼机的示例。我正在使用appCompat和工具栏并扩展appCompat活动 我尝试了一个选项卡主机,但在运行应用程序时它是不可见的 <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="verti

我需要三个选项卡,基本上改变了下面列表视图的排序。我不需要查看寻呼机或任何太复杂的东西,但我只能找到带有查看寻呼机的示例。我正在使用appCompat和工具栏并扩展appCompat活动


我尝试了一个选项卡主机,但在运行应用程序时它是不可见的

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

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

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

        <LinearLayout
             android:id="@+id/tab1"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:orientation="horizontal" />
...

...

听起来你只是想要按钮,而不是标签。但是如果希望它看起来像新的TableAyout和应用程序,则应该能够使用中提供的新TableAyout,但是不需要连接操作来实际分页任何内容,并且可以使用它们来触发排序顺序的更改

您的活动的布局如下所示:

<android.support.design.widget.AppBarLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <include layout="@layout/toolbar" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:visibility="gone"/>

</android.support.design.widget.AppBarLayout>

然后,您可以实现各种onPage*方法,您可以使用这些方法简单地触发排序顺序的更改,而不是让它实际更改您的页面。

“我尝试了一个选项卡主机,但在运行应用程序时它是不可见的”——嗯,您添加了任何选项卡吗?这将出现在Java代码中
TabHost
当然有效,正如
FragmentTabHost
一样。设计支持库也有一个选项卡实现,虽然它可以使用
ViewPager
,但不需要
ViewPager
AFAIK。尽管如此,由于大多数选项卡实现都使用
ViewPager
,因此用户可能希望能够在选项卡之间滑动,即使您认为不需要它。如果您想更改排序,为什么不直接更改排序呢?为什么需要标签?
mTabLayout = mActivity.getTabLayout();
if (mTabLayout != null) {
    // Or manually set if you want
    mTabLayout.setTabsFromPagerAdapter(getPagerAdapter());
    mPageChangeListener = new TabLayout.TabLayoutOnPageChangeListener(mTabLayout);
    // This is the bit that you will not want as that will change pages
    // and you aren't actually changing pages, just listening
    // Leaving these lines in just for reference on what you would do for paging
    // mPager.addOnPageChangeListener(mPageChangeListener);
    mPager.addOnPageChangeListener(this);
    //mTabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mPager) );
}
loadData();