【问题标题】:Swiping Tabs inside a Navigation Drawer Fragment在导航抽屉片段中滑动标签
【发布时间】:2014-03-13 20:16:13
【问题描述】:

我通过引用this tutorial 实现了导航抽屉,现在我想做的是在片段内显示滑动标签。 IE。当我点击导航抽屉中的一个项目时,比如说第一个项目,它应该显示该项目的滑动标签。

如果 item1 是事件,当我单击它时,它应该显示带有标签的滑动标签,例如今天的事件和即将发生的事件。我是一个初学者,我试图用谷歌搜索,我找到的解决方案是使用 sherlock,但我不想使用任何库。请指点我一个正确的教程。我可以在片段中实现视图寻呼机吗?鉴于视图寻呼机将有另外两个片段。

谢谢。

【问题讨论】:

  • 你不需要也可能不应该在你的导航抽屉中有一个片段 - 你可以在抽屉的布局中使用 FragmentViewPager,这可能包含片段,但请考虑你的用户体验设计并确保这是您(/您的用户)想要的。
  • 没错..如果您使用抽屉布局,然后设置您的子视图,您可以轻松实现您想要做的事情。

标签: java android android-fragments android-viewpager


【解决方案1】:

这是我在该评论中所说的抽屉的一个示例。如果你有抽屉布局和子作为 listview 和 viewpager,这就是布局的样子:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#333333"
    tools:context=".MainActivity" >

    <android.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <!-- This List View for the sliding menu -->

    <LinearLayout
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        android:orientation="vertical" >
<!-- If you want to add some more things to your navigation drawer -->
        <!-- <EditText
            android:id="@+id/search_edit_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:hint="Search"
            android:maxLines="1" >
        </EditText> -->

        <ListView
            android:id="@+id/list_slidermenu_child"
            android:layout_width="250dp"
            android:layout_height="match_parent"
            android:background="#303030"
            android:choiceMode="singleChoice"
            android:divider="#272727"
            android:dividerHeight="3dp"
            android:listSelector="@drawable/list_selector"
            android:padding="5dp" />
    </LinearLayout>

</android.support.v4.widget.DrawerLayout>

这就是你的布局的样子:

Test Image http://imageshack.com/a/img22/9166/qh8h.png

现在,在我的示例中,当我单击列表中的任何项目时,视图寻呼机会设置它应该是的视图。

这是你想要的吗?

这是一张新图片:

Test Image http://imageshack.com/a/img600/4421/2khw.png

单击导航中的任何项目时,它会在其后面的视图中显示该内容?

【讨论】:

  • 我正在尝试实现类似谷歌音乐播放器应用程序的东西。我希望在单击时导航抽屉项目将我带到一个活动而不是一个片段。当我这样做时,活动启动但导航抽屉消失。你能告诉我如何将导航抽屉作为基类并在我所有的活动中使用它吗?
  • 你能不能把你正在尝试做的事情画得像一个粗略的草图。我还发布了一张新图片。如果你想要这样的东西,请告诉我。
  • 没错,上图就是我想要的。所以当我点击我的图书馆时,它应该会显示滑动标签,如音乐、专辑、艺术家等。
  • 这是我在你其他帖子上发布的答案
  • 如果这是你想要的,它非常简单.. 两个图像都是相同的并且共享代码类型.. 我有你在这里看到的第一张图像的代码.. 我在等待您对另一篇帖子的回复。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多