
private class task extends AsyncTask<String,VoID,String> { protected String doInBackground(String... params) { ... } protected voID onPostExecute(String result) { ... setRequestedOrIEntation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } protected voID onPreExecute() { ... setRequestedOrIEntation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); }} 当我运行这两行SENSOR和NOSENSOR时,我的屏幕自动水平转换,而不理解为什么.可能会发生
编辑:
我把以下几行检查当前方向,结果如下:
protected voID onPreExecute() { if (getResources().getConfiguration().orIEntation==Configuration.ORIENTATION_LANDSCAPE) { Log.e("TAG","LANDSCAPE"); }else{ Log.e("TAG","PORTRAIT"); } setRequestedOrIEntation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); } Logcat的结果:
LANDSCAPE
但是如果我删除了两行(SetRequestedOrIEntation),我在logcat中得到这个:
PORTRAIT解决方法 只是替换setRequestedOrIEntation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);与setRequestedOrIEntation(ActivityInfo.SCREEN_ORIENTATION_UnspecIFIED);
让我知道发生了什么
入门级
protected voID onPreExecute() { setRequestedOrIEntation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);} 在退出层
protected voID onPostExecute(String result) { ... setRequestedOrIEntation(ActivityInfo.SCREEN_ORIENTATION_UnspecIFIED); } 更新:
有线行为(在你的情况下),但是,任何方式可以使用目前的方向,
int currentOrIEntation = getResources().getConfiguration().orIEntation;
现在在onPreExecute()中设置此方向..
喜欢,
protected voID onPreExecute() { ... int currentOrIEntation = getResources().getConfiguration().orIEntation; if (currentOrIEntation == Configuration.ORIENTATION_LANDSCAPE) { setRequestedOrIEntation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } else { setRequestedOrIEntation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); }} 简单..–)
总结以上是内存溢出为你收集整理的android – 锁定方向,直到Asynctask完成全部内容,希望文章能够帮你解决android – 锁定方向,直到Asynctask完成所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)