外文翻译-基于android平台的校园点餐系统app的设计与实现.docx

上传人:聆听****声音 文档编号:357121 上传时间:2023-04-29 格式:DOCX 页数:10 大小:214.97KB
下载 相关 举报
外文翻译-基于android平台的校园点餐系统app的设计与实现.docx_第1页
第1页 / 共10页
外文翻译-基于android平台的校园点餐系统app的设计与实现.docx_第2页
第2页 / 共10页
外文翻译-基于android平台的校园点餐系统app的设计与实现.docx_第3页
第3页 / 共10页
外文翻译-基于android平台的校园点餐系统app的设计与实现.docx_第4页
第4页 / 共10页
外文翻译-基于android平台的校园点餐系统app的设计与实现.docx_第5页
第5页 / 共10页
外文翻译-基于android平台的校园点餐系统app的设计与实现.docx_第6页
第6页 / 共10页
外文翻译-基于android平台的校园点餐系统app的设计与实现.docx_第7页
第7页 / 共10页
外文翻译-基于android平台的校园点餐系统app的设计与实现.docx_第8页
第8页 / 共10页
外文翻译-基于android平台的校园点餐系统app的设计与实现.docx_第9页
第9页 / 共10页
外文翻译-基于android平台的校园点餐系统app的设计与实现.docx_第10页
第10页 / 共10页
亲,该文档总共10页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

外文翻译-基于android平台的校园点餐系统app的设计与实现.docx

《外文翻译-基于android平台的校园点餐系统app的设计与实现.docx》由会员分享,可在线阅读,更多相关《外文翻译-基于android平台的校园点餐系统app的设计与实现.docx(10页珍藏版)》请在冰点文库上搜索。

外文翻译-基于android平台的校园点餐系统app的设计与实现.docx

1.外文资料翻译译文

Fragement管理器

想象开发一个由两个activity组成的列表明细类应用,其中一个activity管理着记录列表界面,另一个activity管理着记录明细界面。

单击列表中一条记录启动一个记录明细activity实例。

单击后退键销毁明细activity并返回到记录列表activity界面,接下来可以再选择一条记录。

理论上这行得通。

但如果需要更复杂的用户界面呈现及跳转呢?

假设用户正在平板设备上运行Criminallntent应用。

平板以及大尺寸手机通常拥有比较大的屏幕,能够同时显示列表以及明细,至少在水平方位模式下。

图7-2显示模式

假设用户正在手机上查看记录信息,并想查看列表中的下一条记录信息。

如无需返回列表界面,通过滑动屏幕即可查看下一条记录信息就好了。

每滑动一次屏幕,应用便自动切换到下一条记录明细。

可以看出UI设计具有灵活性是以上假设情形的共同点。

即根据用户或设备的需要,activity界面可以在运行时组装,甚至重新组装。

Activity自身并不具有这样的灵活性。

Activity视图可以在运行时切换,但控制视图的代码必须在activity中实现。

因而,各个activity还是得和用户的屏幕紧紧绑定在一起。

采用fragment而不是activity进行应用的UI管理,可绕开Android系统activity规则的限制。

Fragment是一种控制器对象,activity可委派他完成一些任务。

通常这些任务就是管理用户界面。

受管的用户界面可以是一整屏或是屏幕的一部分。

管理用户界面的丘agment又称为UIfragment□他也有自己产生于布局文件的视图。

Fragment视图包含了用户可以交互的可视化UI元素。

activity视图含有可供fragment视图插入的位置。

如果有多个fragment要插入,activity视图也可提供多个位置。

根据应用和用户的需求,可联合使用fragment及activity来组装或重新组装用户界面。

在整个生命周期过程中,技术上来说activity的视图可保持不变。

因此不用担心会违反Android系统activity规则。

一个列表明细应用准备同时显示列表与明细内容,下面我们就来看看该应用是怎么做到这一

点的。

应用里的activity视图是通过列表fragment和明细fragment组装而成的。

明细视图显示所选列表项的明细内容。

选择不同的列表项会显示不同的明细视图,fragment很容易做到这一点。

activity将以一个

明细fragment替换另一个明细fragment,如图7-3所示。

视图切换的过程中,任何activity都无需被销毁。

图7・3明细fragment的切换

用UIfragment将应用的UI分解成构建块,除列表明细应用外,也适用于其他类型的应用。

利用一个个构建块,很容易做到构建分页界面、动画侧边栏界面等更多其他定制界面。

不过,达成这种UI设计的灵活性也是有代价的,即更加复杂的应用、更多的部件管理以及更

多的实现代码。

我们会在第11章和第22章中体会到使用fragment的好处。

现在先来感受下它的复杂性。

图7-4所示的用户界面将由一个名为CrimeFragment的UIfragment进行管理。

CrimeFragment的实例将通过一个名为CrimeActivity的activity来托管。

我们可以暂时把托管理解成activity在其视图层级里提供一处位置用来放置fragment的视图,如图7-5所示。

Fragment本身不具有在屏幕上显示视图的能力。

因此,只有将它的视图放置在activity的视图层级结构中,fragment视图才能显示在屏幕上。

图7・4本章结束时,Criminallntent应用的界面

图7-5CrimeActivity托管着CrimeFragment

Criminallntent是一个大型项目,可通过对象图解来更好地理解它。

图7-6展示了Criminallntent项目对象的整体图解。

无需记住这些对象及其间的关系。

但预先对开发目标有一个清楚地认识将有助于我们的开发。

图7-6Criminallntent应用的对象图解(本章应完成部分)

可以看到,CrimeFragment的作用与activity在GeoQuiz应用中的作用差不多,都负责创建并管理用户界面,与模型对象进行交互。

其中CrimeCrimeFragment以及CrimeActivity是我们要开发的类。

Crime实例代表了某种办公室陋习。

在本章中,一个crime只有一个标题和一个标识ID。

标题

是一段描述性名称,如“有毒的水池垃圾堆”或“某人偷了我的酸奶!

”等。

标识ID是识别Crime实例的唯一元素。

简单起见,本章我们只使用一个Crime实例,并将其存放在CrimeFragment类的成员变量(mCrime)中。

CrimeActivity视图由FrameLayout组件组成,FrameLayout组件为CrimeFragment要显示的视图安排了存放位置。

CrimeFragment的视图由一个LinearLayout组件及一个EditText组件组成。

CrimeFragment类中有一个存储EditText的成员变量(mTitleField)。

mTitleField±设有监听器,当EditText上的文字发生改变时,用来更新模型层的数据。

介绍了这么多,是时候创建新应用了。

选择New—+AndroidApplicationProject菜单项创建新的

Android应用。

如图7-7所示,将应用命名为Criminallntent,包名命名为com.bignerdranch.android.criminalintento编译及目标版本设置为最新的API级别并保证应用兼容运行Froyo系统的设备。

图7-7创建Criminallntent应用

在接下来的对话框中,不勾选创建定制启动器图标,单击Next继续。

然后利用空白activity模板创建activity,单击Next继续。

最后,命名activity为CrimeActivity,单击Finish按钮完成,如图7-8所示。

图7-8配置CrimeActivity

2.外文原文

FragementManager

Youmightimaginethatalist-detailapplicationconsistsoftwoactivities:

onemanagingthelistandtheothermanagingthedetailview.Clickingacrimeinthelistwouldstartaninstanceofthedetailactivity.PressingtheBackbuttonwoulddestroythedetailactivityandreturnyoutothelistwhereyoucouldselectanothercrime.

Thatwouldwork,butwhatifyouwantedmoresophisticatedpresentationandnavigationbetweenscreens?

•ImaginethatyouruserisrunningCriminallntentonatablet.Tabletsandsomelargerphoneshavescreenslargeenoughtoshowthelistanddetailatthesametime-atleastinlandscapeorientation.

Figure7.2Ideallist-detailinterfaceforphoneandtablet

Phone

Tablet

Figure7.3displaymode

•Imaginetheuserisviewingacrimeonaphoneandwantstoseethenextcrimeinthelist.Itwouldbebetteriftheusercouldswipetoseethenextcrimewithouthavingtoreturntothelist.Eachswipeshouldupdatethedetailviewwithinformationforthenextcrime.

WhatthesescenarioshaveincommonisUIflexibility:

theabilitytocomposeandrecomposeanactivity'sviewatruntimedependingonwhattheuserorthedevicerequires.

Activitieswerenotbuilttoprovidethisflexibility.Anactivity'sviewsmaychangeatruntime,butthecodetocontrolthoseviewsmustliveinsidetheactivity.Asaresult,activitiesweretightlycoupledtoaparticularscreenusedbytheuser.

IntroducingFragments

YoucangetaroundtheletterofthelawofAndroidbymovingtheapp'sUImanagementfromtheactivitytooneormorefragments.

Afragmentisacontrollerobjectthatanactivitycandeputizetoperformtasks.Mostcommonly,thetaskismanagingauserinterface.Theuserinterfacecanbeanentirescreenorjustonepartofthescreen.

AfragmentmanagingauserinterfaceisknownasaUIfragment.AUIfragmenthasaviewofitsownthatisinflatedfromalayoutfile.Thefragment'sviewcontainstheinterestingUIelementsthattheuserwantstoseeandinteractwith.

Theactivity'sviewcontainsaspotwherethefragment'sviewwillbeinserted.Oritmighthaveseveralspotsfortheviewsofseveralfragments.

Youcanusethefragment(s)associatedwiththeactivitytocomposeandre-composethescreenasyourappandusersrequire.Theactivity'sviewtechnicallystaysthesamethroughoutitslifetime,andnolawsofAndroidareviolated.

Lefsseehowthiswouldworkinalist-detailapplicationwhendisplayingthelistanddetailtogether.Youwouldcomposetheactivity9sviewfromalistfragmentandadetailfragment.Thedetailviewwouldshowthedetailsoftheselectedlistitem.

Selectinganotheritemshoulddisplayanewdetailview.Thisiseasywithfragments;theactivitywillreplacethedetailfragmentwithanotherdetailfragment(Figure7.3).Noactivitiesneedtodieforthismajorviewchangetohappen.

Figure7.3Detailfragmentisswappedout

UsingUIfragmentsseparatestheUIofyourappintobuildingblocks,whichisusefulformorethanjustlist-detailapplications.Workingwithindividualblocks,itIseasytobuildtabinterfaces,tackonanimatedsidebars,andmore.

AchievingthisUIflexibilitycomesatacost:

morecomplexity,moremovingparts,andmorecode.YouwillreapthebenefitsofusingfragmentsinChapter11andChapter22.Thecomplexity,however,startsnow.

Itmaynotseemlikeaveryexcitinggoaltoshootfor.Justkeepinmindthatthischapterisaboutlayingthefoundationtodobiggerthingslater.

Figure7.4Criminallntentattheendofthischapter

ThescreenshowninFigure7.4willbemanagedbyaUIfragmentnamedCrimeFragment.AninstanceofCrimeFragmentwillbehostedbyanactivitynamedCrimeActivity.Fornow,thinkofhostingastheactivityprovidingaspotinitsviewhierarchywherethefragmentcanplaceitsview(Figure7.5).AfragmentisincapableofgettingaviewonscreenitselfOnlywhenitisplacedinanactivity'shierarchywill

Figure7.5CrimeActivityhostingaCrimeFragment

Criminallntentwillbealargeproject,andonewaytokeepyourheadwrappedaroundaprojectiswithanobjectdiagram.Figure7.6givesyouthebigpictureofCriminallntent.Youdonothavetomemorizetheseobjectsandtheirrelationships,butitisgoodtohaveanideaofwhereyouareheadingbeforeyoustart.

YoucanseethatCrimeFragmentwilldothesortofworkthatyouractivitiesdidinGeoQuiz:

createandmanagetheuserinterfaceandinteractwiththemodelobjects

Figure7.6ObjectdiagramforCriminallntent(forthischapter)

ThreeoftheclassesshowninFigure7.6areclassesthatyouwillwrite:

Crime,CrimeFragment,andCrimeActivity.

AninstanceofCrimewillrepresentasingleofficecrime.Inthischapter,acrimewillhaveonlyatitleandanID.Thetitleisadescriptivename,like"Toxicsinkdump"or"Someonestolemyyogurt!

TheIDwilluniquelyidentifyaninstanceofCrime.

Forthischapter,youwillkeepthingsverysimpleanduseasingleinstanceofCrime.CrimeFragmentwillhaveamembervariable(mCrime)toholdthisisolatedincident.

CrimeActivity^viewwillconsistofaFrameLayoutthatdefinesthespotwheretheCrimeFragmenfsviewwillappear.

CrimeFragmenfsviewwillconsistofaLinearLayoutandanEditText.CrimeFragmentwillhaveamembervariablefortheEditText(mTitleField)andwillsetalisteneronittoupdatethemodellayerwhenthetextchanges.

Creatinganewproject

Enoughtalk;timetobuildanewapp.CreateanewAndroidapplication(New一AndroidApplicationProject).NametheapplicationCriminallntentandnamethepackagecom.bignerdranch.android.criminalintent,asshowninFigure7.7.BuildtothelatestAPIsandensurethattheappiscompatiblewithdevicesrunningFroyo.

Figure7.7CreatingtheCriminallntentapplication

Inthenextdialog,unchecktheboxtocreateacustomlaunchericonandclickNext.Afterthat,choosetocreateanactivityusingtheblankactivitytemplateandclickNext.

Finally,nametheactivityCrimeActivityandclickFinish(Figure7.8).

Figure7.8ConfiguringCrimeActivity

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2