3

下面是我的代码。
我想将其设置为禁用自动更改屏幕方向。
并启用自动更改屏幕方向。

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
        }
    }

我该怎么做?

4

3 回答 3

7

使您的活动在清单中看起来像这样

  <activity
                android:name=".Hello"
                android:label="@string/app_name"
                android:screenOrientation="portrait"   <-- Screen will be forced to have portrait
                android:configChanges="orientation|keyboardHidden|screensize" > <-- No Restart in these cases

ScreenSize 属性似乎是在 4.0 中添加的,所以如果您在 4.0 以下运行,请不要提及它。

于 2012-06-14T07:06:53.210 回答
2
disable auto change screen orientation.And enable auto change screen orientation.

如果你想做at run time

尝试 :

  1. 根据您的需要保留一个布尔标志,如http://thinkandroid.wordpress.com/2009/12/27/handling-configuration-changes-or-not/
  2. 覆盖 onconfigurationchanged,如果它是 true,则将调用传递给 super.onconfigurationchanged,如果 false 不会将调用传递给 super
于 2012-06-14T06:51:40.707 回答
1

在运行时:

当您想阻止传感器时:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

当您要激活时:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);

http://developer.android.com/reference/android/app/Activity.html

于 2012-07-10T08:59:37.177 回答