简体   繁体   English

如何合并主页和导航抽屉?

[英]How to merge home page and Navigation drawer?

I have to design an application like online shopping apps. 我必须设计一个像在线购物应用程序的应用程序。 I made a home page as well as navigation drawer but both are design separately now i need to marge the both activities. 我创建了一个主页以及导航抽屉,但两者都是单独设计的,现在我需要为这两个活动做好准备。 please suggest how to merge it. 请建议如何合并它。

Home

这是主页,我想在左上角添加导航抽屉

Nav 导航

这是我需要在主页上添加的导航抽屉

Both these screens should have their own XML, right? 这两个屏幕都应该有自己的XML,对吧?

So therefore, both can be made into Fragments. 因此,两者都可以制成碎片。 That's Step 1. 这是第1步。

Then, you make a new Activity layout using DrawerLayout. 然后,使用DrawerLayout创建一个新的Activity布局。 You may use the template that Android Studio provides, but that'll include lots of Java code that you may not need, but the XML generated there will give you an idea. 您可以使用Android Studio提供的模板,但这将包含许多您可能不需要的Java代码,但是在那里生成的XML将为您提供一个想法。

The general layout will roughly be 总体布局大致如下

DrawerLayout 

    CoordinatorLayout 
        AppBarLayout 
            Toolbar 
        /AppBarLayout

        FrameLayout  :id = container 

    /CoordinatorLayout

    fragment :class = package.name.YourDrawerFragment

/DrawerLayout

And you use optionally replace the inner FrameLayout with an XML <include> tag if you aren't wanting to use Fragments there. 如果您不想在那里使用Fragments,则可以选择使用XML <include>标记替换内部FrameLayout。

It looks like you already have the Drawer established, so you simply need to load content "behind it" 看起来你已经建立了抽屉,所以你只需要加载内容“在它后面”

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

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