[英]how to set screen orientation from non main activity in android
我是android開發的初學者
我想通過非主要activity
設置screen orientation
我有2節課:-
MainActivity
擴展了AppCompatActivity
在MainActivity
有此method
:
public void setOrintation(){
if (My_Values.STABLE_MODE_ENABLE == 1) {
int orientation = this.getRequestedOrientation();
int rotation = ((WindowManager) this.getSystemService(
Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
switch (rotation) {
case Surface.ROTATION_0:
orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
break;
case Surface.ROTATION_90:
orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
break;
case Surface.ROTATION_180:
orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
break;
default:
orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
break;
}
this.setRequestedOrientation(orientation);
} else {
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
}
public class My_View extends View implements View.OnTouchListener
(類內無) 那我就不能調用MainActivity
setOrintation()
方法
怎么做呢?
也許您可以嘗試使用metod setOrintation()創建接口,並讓MainActivity實現此接口。 在My_View對象中,您將必須發送活動作為此接口
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.