fragments
- 格式:ppt
- 大小:157.00 KB
- 文档页数:5


自从Android 3.0中引入fragments 的概念,其上的是为了解决不同屏幕分辩率的动态和灵活UI设计。
fragments 的设计不需要你来亲自管理view hierarchy 的复杂变化,通过将Activity 的布局分散到frament 中,可以在运行时修改activity 的外观,并且由activity 管理的back stack 中保存些变化。
每一个fragments 都有自己的一套生命周期回调方法和处理自己的用户输入事件。
对应生命周期可参考下面流程:onAttach()->onCreate()->onCreateView()->onActivityCreated()->onStart( )->onResume()此时Fragment就开始运行了。
onPause()->onStop()->onDestoryView()->onDestory()->onDetach()此时Fragment就彻底销毁了。
Fragment生命周期图如下:其中onAttach()和onDetach()用的不是很多,而onCreateView()和onDestoryView()是Fragment生命周期和Activity生命周期不同的。
其他的可以按照Activity生命周期去理解。
下面补充一下Activity的生命周期。
三种系统内置的Fragments系统内置了三种Fragments ,这三种Fragments 分别有不同的应用场景分别为:DialogFragment对话框式的Fragments,可以将一个fragments 对话框并到activity 管理的fragments back stack 中,允许用户回到一个前曾摒弃fragments.ListFragments类似于ListActivity 的效果,并且还提供了ListActivity 类似的onListItemCLick和setListAdapter等功能。
What is sentence fragments?A sentence is defined as a group of words containing a subject, a verb, and a complete thought. If any of these elements is missing,then the group of words isn't a sentence.A fragment is a group of words that is punctuated like a sentence and that is trying to function as a sentence, but one of the necessary elements is missing.How to identify “sentence fragments”?There are several ways to find and correct fragments.◆Does it have a subject?◆Does it have a verb?◆Does it start with a subordinating conjunction or a relative pronoun that keepsthe thought from being complete?If the answer to any of the questions is no, it is a fragment.How to correct “fragment sentence”?Correcting fragments is fairly simple and you have several options.◆For a fragment that is missing a subject or verb, add the missing element.E.g. Pizza afterwards.◆If the problem is a subordinating conjunction, the conjunction can be removedwhich would make the fragment a complete sentence.e.g. Scientists report no human deaths due to excessive caffeine consumption. Although caffeine does cause convulsions and death in certain animals.correct:[2nd sentence = fragment]Scientists report no human deaths due to excessive caffeine consumption,although caffeine does cause convulsions and death in certain animals.◆Another option is to join the fragment to another sentence either before it orafter it in the paragraph creating a complex sentence.E.g. If you want to travel abroad.Quiz yourself to identify which sentence is a complete sentence which sentence is a fragment?1. Then I attended Morris Junior High. A junior high that was a bad experience.2. He talked for fifty minutes without taking his eyes off his notes. Like other teachers in that department, he did not encourage students' questions.3. Within each group, a wide range of features to choose from. It was difficult to distinguish between them.4. It can be really embarrassing to be so emotional. Especially when you are on your first date, you feel that you should be in control.5. In the seventh grade every young boy goes out for football. To prove to himself and his parents that he is a man.6. As Christmas grows near, I find myself looking back into my childhood days at fun-filled times of snowball fights. To think about this makes me happy.7. The small, one-story houses are all the same size and style. With no difference except the color.When can you use sentence fragments?Sentence fragments are often intentional in◆newspaper and magazines ads.Fragment:(1)Faster! Better! No money down! (ads)(2)The Market Outlook: More Plunges, or a Year-End Rally?(3) Rising From the Rubble of Sichuan Quake◆When you write conversations, because you are writing how people speak, andpeople very seldom speak in complete sentences.___"What's going to happen to Boyde, now that Bill is dead?"___"Don't know."___"Do you care?"___"Nope. Don't know and don't care!"◆In poemsFragments have been a significant feature of the works of three groups of poets: the American Transcendentalists, the Imagists, and a range of Post-modern poets.In the following passage from the second section of Song of Myself, Whitman uses a catalogue consisting of more than twenty noun phrases (NPs):e.g.The smoke of my own breath,Echoes, ripples, buzz'd whispers, love-root, silk-thread, crotch and vine,My respiration and inspiration, the beating of my heart, the passing of blood and air through my lungs,The sniff of green leaves and dry leaves, and of the shore anddark-color'd sea-rocks, and of hay in the barn,The sound of the belch'd words of my voice loos'd to the eddies of the wind,A few light kisses, a few embraces, a reaching around of arms,The play of the shine and shade on the trees as the supple boughs wag,The delight alone or in the rush of the streets, or along the fields and hill-sides, The feeling of health, the full-moon trill, the song of me rising from bedand meeting the sun. (29, ll. 21-28)Whatever their goals are in using fragments, all of these poets assert that the nature of raw human perception is fragmentary.ConclusionWhile sentence fragments are acceptable in these contexts, you should avoid using sentence fragments in research papers,business or professional reports, and job applications.。