Android中导航抽屉和选项卡的最佳实践

Android中导航抽屉和选项卡的最佳实践,android,navigation-drawer,android-tablayout,android-tabs,Android,Navigation Drawer,Android Tablayout,Android Tabs,我正在尝试在Android中创建选项卡。我的主要活动包含一个带有导航抽屉(Listview)的视图和内容的框架布局,因此我需要为每个菜单项使用片段。我认为这是一个通常的方法来建立一个应用程序与“左侧滑出”菜单 在我的主片段(第二个菜单项app.fragment)中,我需要一个带有2个选项卡的选项卡控件。在每个选项卡中,我需要加载一个片段(app.fragment,因为1 fragment包含一个map v2,它仅适用于app.fragment(在我的例子中))。我有一个rab_映射视图和一个ta

我正在尝试在Android中创建选项卡。我的主要活动包含一个带有导航抽屉(Listview)的视图和内容的框架布局,因此我需要为每个菜单项使用片段。我认为这是一个通常的方法来建立一个应用程序与“左侧滑出”菜单

在我的主片段(第二个菜单项app.fragment)中,我需要一个带有2个选项卡的选项卡控件。在每个选项卡中,我需要加载一个片段(app.fragment,因为1 fragment包含一个map v2,它仅适用于app.fragment(在我的例子中))。我有一个rab_映射视图和一个tab_列表视图片段

tab_Mapview和tab_Listview选项卡片段都是app.Fragment片段。 我挣扎了两天才完成这件事。。。但我无法解决它:-(我经常遇到与support.v4有关的问题………Fragment和app.Fragment兼容性问题,或者我无法在片段中找到解决方案(仅在活动中,我无法在FrameLayout中加载的内容)

我发现并尝试了一些东西:

  • 塔伯斯特
  • 表格布局
  • 操作栏选项卡
在我的情况下,哪一个是正确的,我如何以正确的方式实施它


我的愿望有点不符合(上面是选项卡,下面是布局中的3个按钮)

我的主要活动布局

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

    <FrameLayout
        android:id="@+id/fr_content_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </FrameLayout>
    <ListView
        android:id="@+id/lv_menu"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="left">
    </ListView>
</android.support.v4.widget.DrawerLayout>

我是android的新手,所以如果有人能发布一个简单的(有效的)示例,那就太好了:

  • 主要活动,左侧有工作滑出菜单
  • 当我点击1个菜单项时,主界面将打开
  • 主片段包含一个带有2个选项卡的选项卡控件
  • 每个选项卡都会打开一个app.fragment片段

如果可能的话,我想在这种情况下使用最佳实践。如果有人愿意做这个简单的例子,那就太好了,这样我就可以详细了解这种情况下的最佳实践是如何运作的,我也可以在其他项目中使用它。

寻找相同的方法,你有什么收获吗,如果有,请分享你正在寻找菜单和打开的菜单项中有一个需要显示tabview?,我已经开始工作了。我使用EVERYWHERE
android.support.v4.app.XXX
组件(Fragment,maps-aso)
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="aaeu.app.presentationlayer.MainFragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="450dp"
        android:orientation="vertical">
        <android.support.design.widget.TabLayout
            android:id="@+id/sliding_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="scrollable" />
        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="0px"
            android:layout_weight="1"
            android:background="@android:color/white" />
    </LinearLayout>


    <LinearLayout
        android:weightSum="3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="450dp">
        <Button
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/all_alerts"
            android:id="@+id/btn_all_alerts"/>
        <Button
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/amber_alerts"
            android:id="@+id/btn_ambert_alerts"/>
        <Button
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/endangered_missings"
            android:id="@+id/btn_missings"/>
    </LinearLayout>
</FrameLayout>
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.fragment_main, container, false);

    // Get the ViewPager and set it's PagerAdapter so that it can display items
    tabLayout = (TabLayout)v.findViewById(android.R.id.tabhost);
    ViewPager viewPager = (ViewPager) v.findViewById(R.id.viewpager);
    viewPager.setAdapter(new SampleFragmentPagerAdapter(getFragmentManager(), getContext()));

    // Give the TabLayout the ViewPager
    TabLayout tabLayout = (TabLayout) v.findViewById(R.id.sliding_tabs);
    tabLayout.setupWithViewPager(viewPager);

    return v;
}