更新时间:2021-10-14 22:37:53
在Android上,我们可以使用 Android 3.2引入的 屏幕尺寸选择器 ,以定义要使用的布局. 有关更多详细信息,请参见 http://android -developers.blogspot.in/2011/07/new-tools-for-managing-screen-sizes.html .以下代码段已从同一链接中提取:
On Android we can use screen size selector, introduced from Android 3.2, to define which layout to use. More details available at http://android-developers.blogspot.in/2011/07/new-tools-for-managing-screen-sizes.html. Following code snippet has been extracted from the same link :
public class MyActivity extends Activity
{
@Override protected void onCreate(Bundle savedInstanceState)
{
super.onCreate();
Configuration config = getResources().getConfiguration();
if (config.smallestScreenWidthDp >= 600)
{
setContentView(R.layout.main_activity_tablet);
}
else
{
setContentView(R.layout.main_activity);
}
}
}
关于大小配置的另一个很好的参考是保留分隔符.有关详细信息,请参见: http://www.vanteon.com/downloads/Scaling_Android_Apps_White_Paper.pdf
Another good reference for size configuration is keeping separator. This is explain in details at : http://www.vanteon.com/downloads/Scaling_Android_Apps_White_Paper.pdf