我是Android开发的初学者
我想从非主screen orientation
activity
我有两节课: -
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()
方法
如何做到这一点?
答案 0 :(得分:0)
也许您可以尝试使用metod setOrintation()创建接口,并让MainActivity实现此接口。在My_View对象中,您必须以此接口
发送活动