我是android开发的初学者

我想从非主screen orientation设置activity

我有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对象中,您必须将活动发送为该接口

08-28 18:07