Android的导航抽屉和片段 [英] Android Navigation Drawers and Fragments

查看:140
本文介绍了Android的导航抽屉和片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚创建使用Eclipse和Android SDK的一个新项目。该项目现在包含导航抽屉和样品3导航项目的空白活动。

RES /布局,我现在有 activity_main.xml中 fragment_main.xml fragment_navigation_drawer.xml

我的问题是 - 依据又是什么在导航抽屉选择显示不同的内容,我做这将代替 fragment_main.xml ,还是我加载 fragment_main.xml

解决方案

每个片段项目创建新的布局,如果片段意见是不同的。

当选择了一个抽屉里的项目,替换活动的片段。

所以,你的活动布局应该有,抽屉父布局的FrameLayout容器的ListView 的孩子。

当一个项目被选中,替换片段活动布局的容器

I have just created a new project using Eclipse and the Android SDK. The project now contains a blank activity with navigation drawers and its sample 3 navigation items.

Under res/layout, I currently have activity_main.xml, fragment_main.xml and fragment_navigation_drawer.xml.

My question is -- to display different content based on what is chosen in the navigation drawer, do I make a new view that will be loaded in place of the fragment_main.xml, or do I load the view inside of fragment_main.xml?

解决方案

Create new layout for each Fragment items if Fragment views are different

When an drawer item is selected, replace the fragment in the activity.

So your activity layout should have , Drawer as parent layout and a FrameLayout container and ListView as child.

When an item is selected, replace the Fragment in the container of Activity Layout

这篇关于Android的导航抽屉和片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆