活动与片段 [英] Activities vs Fragments

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

问题描述

我想设计,其中导航通过应用程序的几个主要屏幕的主要模式使用标签的应用程序。我基本上是抄在这里的教程中的方法:的 http://www.androidhive.info/2013/10/android-tab-layout-with-swipeable-views-1/

I'm trying to design an application where the main mode of navigation through the application's several primary screens uses Tabs. I've basically copied the approach shown in the tutorial here: http://www.androidhive.info/2013/10/android-tab-layout-with-swipeable-views-1/

然而,在一些屏幕有,都应该揭开序幕全屏页面可点击的元素(标签不应再在页面的顶部)。我已经能够通过创建新画面新的活动得到这个工作,但我相信我想要使用新的屏幕片段,因为在平板电脑的布局,我想在主屏幕的旁边出现新的屏幕,而不是取代它。我都没有成功这样做。如果任何人都可以就如何得到一个单一的活动运行具有基于选项卡的导航等片段片段不具有的标签导航实例或指针。

However, on some of these screens there are clickable elements that are supposed to kick off a full-screen page (the tabs should no longer at the top of the page). I've been able to get this working by creating a new activity for the new screen, but I believe I want to use a fragment for the new screen because in a tablet layout, I want the new screen to appear beside the main screen rather than replacing it. I haven't been successful doing this. If anyone can give examples or pointers on how to get a single activity to run fragments with tab-based navigation and other fragments that that don't have the tab navigation.

在此类似,我也有一个设置屏幕从选项菜单中访问。是否设置屏幕像这样典型的做法是活动或片段?

In a similar vein, I also have a settings screen accessible from the Options Menu. Are settings screens like this typically done as activities or fragments?

在此先感谢。

推荐答案

您必须将应用程序设计有两种方式。

You have to design your application in two ways.

首先,你应该知道,如果你正在运行大型设备(平板电脑),小型的(智能手机)。 也许你认为由preparing两个不同的布局,在布局的资源配置文件夹,智能手机和第二布局一种布局在<$​​ C $ C>布局XLARGE 更大的设备资源文件夹。

Firstly you should know if you are running big device (tablet) or smaller one (smartphone). You could make that by preparing two different layouts, one layout in layouts resource folder for smartphone and second layout in layout-xlarge resource folder for bigger devices.

在更小的布局使只有一个容器1的片段(片段列表例如)。在布局XLARGE 文件夹更大的布局,你不需经过有两个容器之一片段,列表和第二的片段,内容。

In smaller layout make only one container for one fragment (list fragment for example). In bigger layout in layout-xlarge folder you coul have two containers one for fragment with list and second for fragment with content.

的onCreate 方法,你可以看到,如果您使用的是多面板布局与否。 如果存在较大的布局你的secod窗格是例如 R.id.right_panel 。你只要 findViewById(R.id.right_panel),如果这是,你知道你不运行多窗格。

In onCreate method you could see if you are using multi pane layout or not. If your secod pane in bigger layout is for example R.id.right_panel. You just make findViewById(R.id.right_panel) and if this is null, you know that you are not running multi pane.

现在,如果你是在多窗格中,名单上的pressing项目应该通知的活动,活动应该改变/另外一个人更换正确的片段。

Now if you are in multi pane, pressing item on the list should notify activity, and activity should change/replace right fragment with another one.

如果您不在多窗格中,名单上的pressing项目应打开新活动与内容只有一个片段。

If you are not in multi pane, pressing item on the list should open new activity with only one fragment of content.

有这个simmilar解决方案的很多教程如链接链接

There are many tutorials of this of simmilar solutions like link or link

问候

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

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