当我按下按钮旋转屏幕

时间:2015-12-23 18:13:55

标签: android screen

我想编写以下代码 当我按下按钮旋转屏幕时,当Adgd后退按钮关闭屏幕旋转时,请谢谢

1 个答案:

答案 0 :(得分:3)

此代码可以帮助您:

Button buttonSetPortrait = (Button)findViewById(R.id.setPortrait);
Button buttonSetLandscape = (Button)findViewById(R.id.setLandscape);

buttonSetPortrait.setOnClickListener(new Button.OnClickListener(){

   @Override
   public void onClick(View arg0) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
   }

});

buttonSetLandscape.setOnClickListener(new Button.OnClickListener(){

   @Override
   public void onClick(View arg0) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
   }

});