简体   繁体   English

将带有片段的 Tablayout 作为子片段嵌套在导航抽屉中的片段内

[英]Nesting a Tablayout With Fragments as Child fragments inside an Fragment from Navigation drawer

I have implemented a Navigation drawer with Fragments Frag_A, Frag_B, Frag_C and Frag_D successfully, But I want inside Fragment B to put A Tablayout with 3 TABS (Child Fragments) child_Frag_1, child_Frag_2, child_Frag_3我已经成功实现了一个带有 Fragments Frag_A、Frag_B、Frag_C 和 Frag_D 的导航抽屉,但我希望在 Fragment B 中放置一个带有 3 个 TABS(子片段)child_Frag_1、child_Frag_2、child_Frag_3 的 Tablayout

Any Links on how to succesfully achive this with child_Frag_1, child_Frag_2 and child_Frag_1 displaying the content有关如何通过 child_Frag_1、child_Frag_2 和 child_Frag_1 显示内容成功实现此目标的任何链接

You can use TabLayout as parent to your TabItems with FrameLayout to hold the actual fragment:您可以使用 TabLayout 作为带有 FrameLayout 的 TabItems 的父级来保存实际的片段:

<android.support.design.widget.TabLayout  
        android:id="@+id/tabLayout"  
        android:layout_width="match_parent"  
        android:layout_height="wrap_content"  
        android:background="#7367">  
  
        <android.support.design.widget.TabItem  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:text="Home" />  
  
        <android.support.design.widget.TabItem  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:text="Java" />  
  
        <android.support.design.widget.TabItem  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:text="Android" />  
  
        <android.support.design.widget.TabItem  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:text="Php" />  
    </android.support.design.widget.TabLayout>  
  
    <FrameLayout  
        android:id="@+id/frameLayout"  
        android:layout_width="match_parent"  
        android:layout_height="455dp"  
        app:layout_constraintEnd_toEndOf="parent"  
        app:layout_constraintStart_toStartOf="parent"  
        app:layout_constraintTop_toBottomOf="@+id/tabLayout">  
  
    </FrameLayout>  
</android.support.constraint.ConstraintLayout>  

For better understanding and for the other detail on how you navigate through your tabs, see this simple tutorial that use the same thing you want to do, except the drawer, which make no problem, you can treat the fragment that host the TabLayout as normal activity like in this tutorial.为了更好地理解和有关如何浏览选项卡的其他详细信息,请参阅这个简单的 教程,它使用您想做的相同的事情,除了抽屉,这没有问题,您可以将托管 TabLayout 的片段视为正常本教程中的活动。

Note: I highly recommend you to use the new navigation component of Android Jetpack Architecture in this cases, it handle all the TROUBLE for you, like navigating and handling the backstack and a lot of other benfits, you can check the docs for more info about it.注意:在这种情况下,我强烈建议您使用 Android Jetpack 架构的新导航组件,它会为您处理所有麻烦,例如导航和处理 backstack 以及许多其他好处,您可以查看文档以获取更多信息它。

Enjoy !享受 !

You can use the Adapters.您可以使用适配器。 You just need to create 1 layout and the adapter will reflect as many layouts or views as you want.您只需要创建 1 个布局,适配器就会根据需要反映尽可能多的布局或视图。 You can learn a lot about adapters on the internet.您可以在 Internet 上了解很多有关适配器的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM