根据屏幕分辨率不同的布局-Android [英] Different layouts according to screen resolution -Android
问题描述
我试图使用不同的屏幕分辨率不同的布局
I am trying to use different layouts for different screen resolution
和我已经成功做到了。
我的问题是,我只需要对于大型和XLARGE布局横向方向
My problem is, I need only Landscape orientation for Large and Xlarge Layouts
和肖像用于正常和小。我使用的仅用于布局的大型土地和布局,XLARGE土地我的
and Portrait for Normal and Small. I am using only Layout-large-land and Layout-xlarge-land in my
res文件夹,它需要肖像also.Similarly对正常和小花费肖像连同
res folder, it takes portrait also.Similarly for Normal and small it takes portrait along with
景观。那么,如何做到这一点编程设定的方向,根据屏幕分辨率
landscape. So How do i do that programatically set the orientation according to screen resolution
在Java文件??
有人可以帮助我?
推荐答案
您需要在活动的onCreate方法调用这样的:
you need to call this in your Activity's onCreate Method:
if ((this.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) <= Configuration.SCREENLAYOUT_SIZE_NORMAL) {
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
这篇关于根据屏幕分辨率不同的布局-Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!