问题描述
- 设置自动旋转屏幕方向的问题
-
我想设置禁止自动旋转屏幕方向。还有能够自动选择屏幕的方向的功能。如何实现?class NewLoad extends AsyncTask<String, String, String> { @Override protected void onPreExecute() { super.onPreExecute(); progDailog = new ProgressDialog(this); progDailog.setMessage("test"); progDailog.setIndeterminate(false); progDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progDailog.setCancelable(false); progDailog.show(); //set disable auto change } @Override protected String doInBackground(String... aurl) { //do something return null; } @Override protected void onPostExecute(String unused) { super.onPostExecute(unused); progDailog.dismiss(); //set enable auto change } }
解决方案
配置文件中对Activity节点添加android:screenOrientation属性(landscape是横向,portrait是纵向),
代码里强制设置如横屏
if(getRequestedOrientation()!=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
时间: 2024-10-21 10:49:04