在机器人工作室fragment_main和activity_main布局 [英] fragment_main and activity_main layouts in Android Studio

查看:126
本文介绍了在机器人工作室fragment_main和activity_main布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我感到困惑与Android的工作室生成的两个布局文件。 (fragment_main.xml和activity_main.xml)

I am confused with the two layout files that are generated by the Android Studio. (fragment_main.xml and activity_main.xml)

我用activity_main.xml。要使用activity_main.xml我需要注释掉

I use activity_main.xml. To use activity_main.xml I need to comment out

if(savedInstanceState==null){...} //in onCreate(), Otherwise it will not display

然后,我可以用activity_main.xml。

Then I can use activity_main.xml.

有人能解释我

  1. 在使用Fragment_main.xml

  1. when to use Fragment_main.xml

优点同时使用的布局。

如何正确使用它们。(如果我不注释掉上面的行不会显示activity_main.xml,相反,它表明fragment_main布局。这意味着我需要建立在fragment_main.xml的接口。)

How to use them correctly.(If I do not comment out above line it will not display activity_main.xml, instead it shows fragment_main layout. That means I need to create the interface in the fragment_main.xml.)

感谢。

推荐答案

以下是使用片段的利益(进行分段的活动):

Following are the benefits using Fragments(Fragmenting your Activities) :

  1. 多模式支持:如果你的应用程序支持横向和纵向模式或平板设备等。考虑像你有一个列表视图,另一个是在您的应用程序的详细信息页面。你可以让两个片段之一,列表视图和一个细节,而不是两个活动,并可以组合在一起的景观和平板电脑,而不是使一个又一个活动片剂。对Android的设置来看看屏幕的平板电脑。

  1. Multiple mode supports : Like if your application supports landscape and portrait mode or tablet devices. Consider something like you have a list view and another is the details page in your app. You can make two fragments one with list view and one with details instead of two activities and can group together in landscape and in tablet devices instead of making an another activity for tablet. Have a look on android Settings screen in tablet.

自定义视图:有一些情况下,我们需要创建一些自定义的意见,但与自定义视图的问题是保持状态,所以不是你可以使用片段,如果他们在你需要适合

Custom Views : There are some scenarios where we need to create some custom views but the issue with custom views are maintaining the state so instead you can use fragment if they fits in your needs.

应用程序导航:滑动抽屉导航处理。打开谷歌播放设备中的一个检查滑动导航。如果你点击任何的滑动导航条中可用的选项,你不会看到任何活动开始攻上的项目。因为它们都是应用程序的俯视图,在这种情况下,你可以有一个活性的片段,并改变他们的自来水。

App Navigation : Sliding drawer navigation handling. Open Google Play in your device an check the sliding navigation. If you tap on any of the option available in sliding navigation bar, you wont see any activity started on tapping on the items. As they all are top view of app,in such scenarios you can have an Activity with fragment and change them on tap .

重用的意见:一旦你创建你的片段,你可以在运行时使用它们的任何活动连接它们在你的活动

Reuse the views : Once you Create your Fragment you can use them in any activity at run time attaching them in your activity.

有许多其他好处,你会发现他们一旦你开始使用。

There are many other benefits, you will find them once you start using.

有一个很好的解释,在这里对Android开发的空间:

There is a nice explanation over here on android developer's space :

<一个href="http://developer.android.com/guide/components/fragments.html">http://developer.android.com/guide/components/fragments.html

阅读本而定。

这篇关于在机器人工作室fragment_main和activity_main布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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