简体   繁体   English

如何在 Android 中使用导航抽屉获取滚动活动(材料设计)

[英]How to get a Scrolling Activity With Navigation Drawer in Android (Material Design)

I've been interested in material design and wanted to build a layout for the main page of my app so that it looks like the default template for Scrolling Activity but also has a Navigation Drawer like the default template for Navigation Drawer Activity for easy navigation.我对材料设计很感兴趣,想为我的应用程序的主页构建一个布局,使其看起来像滚动活动的默认模板,但也有一个导航抽屉,就像导航抽屉活动的默认模板,以便于导航。

As an example, Google's Play Music app already does this sort of thing.例如,Google 的 Play Music 应用程序已经在做这种事情。 Have a look:看一看:

Scrolling list with a banner and a FAB at the top ,顶部带有横幅和 FAB 的滚动列表

Navigation Drawer, accessed by swiping from over to the left导航抽屉,通过从上方向左滑动来访问

I've searched everywhere and could find a direct way for implementing such a layout.我到处搜索,可以找到实现这种布局的直接方法。 So I tried doing it on my own and with some changes here and there in the default templates of Scrolling Activity and the Navigation Drawer Activity I was able to achieve something along those lines but not exactly what I was looking for.所以我尝试自己做,并在滚动活动和导航抽屉活动的默认模板中进行了一些更改,我能够沿着这些方向实现一些东西,但并不完全是我想要的。

I was hopping if someone could present a better way of doing it.如果有人可以提出更好的方法,我就在跳。

You can still use the DrawerLayout supplied in the Android support library with a FrameLayout and ListView to achieve the Navigation drawer.您仍然可以使用 Android 支持库中提供的 DrawerLayout 与 FrameLayout 和 ListView 来实现导航抽屉。 In the FrameLayout, you will display a Fragment which takes a ScrollView to display scrollable content.在 FrameLayout 中,您将显示一个 Fragment,它采用 ScrollView 来显示可滚动内容。 The Fragment can also have other widgets that let you customize your layout. Fragment 还可以有其他小部件,可让您自定义布局。

I've got exactly what I wanted, you simply need to include Scrolling Activity's layout inside the layout of Navigation Drawer Activity and it works nicely.我已经得到了我想要的东西,你只需要在 Navigation Drawer Activity 的布局中包含 Scrolling Activity 的布局,它就可以很好地工作。

You can use the default templates for these activities given in the Android Studio to save yourself some time or start from scratch.您可以使用 Android Studio 中提供的这些活动的默认模板来节省一些时间或从头开始。

Let me know if anyone needs some code and I will be more than happy to post it :)如果有人需要一些代码,请告诉我,我将非常乐意发布它:)

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

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