https://developer.android.com/training/basics/fragments/index.html

encapsulate vt. 压缩;将…装入胶囊;将…封进内部;概述

behaves vi. 表现;(机器等)运转;举止端正;(事物)起某种作用

You can create these modules with the Fragment class, which behaves somewhat like a nested activity that can define its own layout and manage its own lifecycle.

你可以定义一个fragment,fragment就像一个嵌套的activity,可以定义自己的布局和生命周期

specifies n. 指定

https://developer.android.com/training/basics/fragments/creating.html

modular adj. 模块化的;模数的;有标准组件的

One difference when creating a Fragment is that you must use the onCreateView() callback to define the layout. In fact, this is the only callback you need in order to get a fragment running.

意思就是说对于一个fragment来说,onCreateView()是你必须要重写的方法

https://developer.android.com/training/basics/fragments/fragment-ui.html

handset n. 手机,电话听筒

Conversely adv. 相反地

If your activity allows the fragments to be removed and replaced, you should add the initial fragment(s) to the activity during the activity's onCreate()method.

An important rule when dealing with fragments—especially when adding fragments at runtime—is that your activity layout must include a container Viewin which you can insert the fragment.

如果你需要你的Fragment可以被动态的添加或者删除,那么你必须在Activity的OnCreate()方法中初始化它。

如果你的activity要动态的增删fragment,那么布局中必须要有一个view布局来装载这个fragment。

这里提一句,Google的教程,真的像是再教小孩子学习,可能是需要考虑到全世界各地的开发者吧,浅显易懂,然而,如果能够学好Google所有的教程,也可以称为一个所谓的大牛了。

Inside your activity, call getSupportFragmentManager() to get a FragmentManager using the Support Library APIs. Then call beginTransaction() to create a FragmentTransaction and call add() to add a fragment.

You can perform multiple fragment transaction for the activity using the same FragmentTransaction. When you're ready to make the changes, you must call commit().

浅显易懂,就不翻译了

procedure n. 程序,手续;步骤

Keep in mind that when you perform fragment transactions, such as replace or remove one, it's often appropriate to allow the user to navigate backward and "undo" the change. To allow the user to navigate backward through the fragment transactions, you must call addToBackStack() before you commit the FragmentTransaction.

transaction n. 交易;事务;办理;会报,学报

如果需要让用户执行返回操作,那么你必须在提交事务之前调用addToBackStack()方法

Note: When you remove or replace a fragment and add the transaction to the back stack, the fragment that is removed is stopped (not destroyed). If the user navigates back to restore the fragment, it restarts. If you do not add the transaction to the back stack, then the fragment is destroyed when removed or replaced.

如果替换或者移出一个fragment并且加入了事务栈,那么这个fragment只是被stop,并没有销毁,当用户点击返回时,会被重新启动,但是如果没有加入事务栈,那么这个fragment在replace的时候就直接被销毁了。

https://developer.android.com/training/basics/fragments/communicating.html

Often you will want one Fragment to communicate with another, for example to change the content based on a user event. All Fragment-to-Fragment communication is done through the associated Activity. Two Fragments should never communicate directly.

fragment和fragment的通信必须通过关联的activity,两个fragment不应该直接通信

你可能感兴趣的:(https://developer.android.com/training/basics/fragments/index.html)