[英]How to enable screen rotation programatically in android?
I need to enable this function for an activity of mine:我需要为我的活动启用此功能:
I want it to be like this:我希望它是这样的:
when it's like this:当它是这样的:
please note that I DON'T want to set it fixed as PORTRAIT, LANDSCAPE or any other orientation, I really want the user to rotate the device freely.请注意,我不想将其设置为固定为纵向、横向或任何其他方向,我真的希望用户可以自由旋转设备。
Do I need to request any permission on manifest?我需要对清单申请任何许可吗? Is it even posible to do that?
甚至有可能这样做吗? I couldn't find anything that actually work, for example:
我找不到任何实际工作的东西,例如:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
just does not work at all.根本不起作用。
Do you want to change the device settings or just for your app?您要更改设备设置还是仅更改您的应用程序?
If you want to change it for your app:如果您想为您的应用更改它:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
setContentView(view);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.