Android 4.0 ( Ice Cream Sandwich) 即将到来 你准备好了吗
日前developer.android.com 的首席技术作家 Scott Main 为 Android Developers Blog 撰写了一篇文章介绍如何把为Android 3.0平板开发的程序移植到即将发布的Ice Cream Sandwich 系统上.
在文中 Scott Main 还提到,Android系统从Ice Cream Sandwich以后都将保持让同一个App运行在各种尺寸的屏幕上,让开发者不再为屏幕尺寸不统一而烦恼!
但是 那些为 Honeycomb 系统而开发的平板程序,是针对大尺寸屏幕设计的, 在Ice Cream Sandwich 尚未发布的时候 这些程序还不会对用户照成什么干扰, 而 在Ice Cream Sandwich发布以后 就不是这么一回事了, 由于Android系统是向后兼容的, 所以等Ice Cream Sandwich系统发布以后,有用户使用该系统的小屏幕手机来使用你为Honeycomb开发的大屏幕程序就会出现问题. 为了避免这种伤害用户的行为,现在你就可以开始修改你的程序了.
对于那些专门为Honeycomb平板而开发的程序,需要做两件事情:
1.阻止该程序安装到小屏幕设备上;
2.修改该程序 使其可以兼容小屏幕设备
只支持Honeycomb平板
如果你的程序只支持大屏幕的平板,则修改程序是比较简单的,只需要在 manifest 文件中添加 <supports-screens> 标签即可:
<manifest ... > <supports-screens android:smallScreens="false" android:normalScreens="false" android:largeScreens="false" android:xlargeScreens="true" android:requiresSmallestWidthDp="600" /> <application ... > ... </application></manifest>

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <fragment android:id="@+id/list_frag" android:layout_width="match_parent" android:layout_height="match_parent"/></FrameLayout>
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/frags"> <fragment android:id="@+id/list_frag" android:layout_width="@dimen/titles_size" android:layout_height="match_parent"/> <fragment android:id="@+id/details_frag" android:layout_width="match_parent" android:layout_height="match_parent" /></LinearLayout>
/** This is a callback that the list fragment (Fragment A) calls when a list item is selected */public void onItemSelected(int position) { DisplayFragment fragB = (DisplayFragment) getFragmentManager() .findFragmentById(R.id.display_frag); if (fragB == null) { // DisplayFragment (Fragment B) is not in the layout, // start DisplayActivity (Activity B) // and pass it the info about the selected item Intent intent = new Intent(this, DisplayActivity.class); intent.putExtra("position", position); startActivity(intent); } else { // DisplayFragment (Fragment B) is in the layout, tell it to update fragB.updateContent(position); }}