大佬教程收集整理的这篇文章主要介绍了android – 锁定方向,直到Asynctask完成,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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
让我知道发生了什么
入门级
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完成所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。