资源描述:
《【android开发wiki】入门篇多设备支持(二):多屏幕支持 -supporting different screens》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、eoe移动开发者社区http://www.eoe.cn/原文地址:http://developer.android.com/training/basics/supporting-devices/screens.htmlAndroidcategorizesdevicescreensusingtwogeneralproperties:sizeanddensity.Youshouldexpectthatyourappwillbeinstalledondeviceswithscreensthatrangeinb
2、othsizeanddensity.Assuch,youshouldincludesomealternativeresourcesthatoptimizeyourapp’sappearancefordifferentscreensizesanddensities.Therearefourgeneralizedsizes:small,normal,large,xlargeAndfourgeneralizeddensities:low(ldpi),medium(mdpi),high(hdpi),extrah
3、igh(xhdpi)Todeclaredifferentlayoutsandbitmapsyou'dliketousefordifferentscreens,youmustplacethesealternativeresourcesinseparatedirectories,similartohowyoudofordifferentlanguagestrings.Alsobeawarethatthescreensorientation(landscapeorportrait)isconsideredav
4、ariationofscreensize,somanyappsshouldrevisethelayouttooptimizetheuserexperienceineachorientation.CreateDifferentLayoutsTooptimizeyouruserexperienceondifferentscreensizes,youshouldcreateauniquelayoutXMLfileforeachscreensizeyouwanttosupport.Eachlayoutshoul
5、dbesavedintotheappropriateresourcesdirectory,namedwitha-eoe移动开发者社区http://www.eoe.cn/suffix.Forexample,auniquelayoutforlargescreensshouldbesavedunderres/layout-large/.Note:Androidautomaticallyscalesyourlayoutinordertoproperlyfitthescreen.Thus
6、,yourlayoutsfordifferentscreensizesdon'tneedtoworryabouttheabsolutesizeofUIelementsbutinsteadfocusonthelayoutstructurethataffectstheuserexperience(suchasthesizeorpositionofimportantviewsrelativetosiblingviews).Forexample,thisprojectincludesadefaultlayout
7、andanalternativelayoutforlargescreens:1.MyProject/2.res/3.layout/4.main.xml5.layout-large/6.main.xmlThefilenamesmustbeexactlythesame,buttheircontentsaredifferentinordertoprovideanoptimizedUIforthecorrespondingscreensize.Simplyreferencethelayoutfileinyour
8、appasusual:1.@Override2.protectedvoidonCreate(BundlesavedInstanceState){3.super.onCreate(savedInstanceState);4.setContentView(R.layout.main);5.}eoe移动开发者社区http://www.eoe.cn/Thesystemloadsthelayoutfilefromtheappropriatelayou