我想設置禁止自動旋轉屏幕方向。還有能夠自動選擇屏幕的方向的功能。如何實現?
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);
}