See the andoird screen switch today because it is a normal thing to switch landscape in the game.
First, if we don't want to switch directions, we can add the properties of the activity in Androidmainfest.xml.
The Android:sreenorientation property value portrait represents the vertical landscape represents the horizontal
But I don't want to do this, I add the horizontal and vertical buttons to make the screen switch.
Add two buttons to implement in a listener function
Setrequestedorientation (activityinfo.screen_orientation_landscape); Toggle Level
Setrequestedorientation (activityinfo.screen_orientation_portrait); Toggle Vertical
Attached code:
button_1= (Button) Findviewbyid (R.id.horizon);
Button_2= (Button) Findviewbyid (r.id.vertical);
Button_1.setonclicklistener (New View.onclicklistener () {
@Override
Toggle Landscape
public void OnClick (view view) {
Setrequestedorientation (Activityinfo.screen_orientation_landscape);
}
});
Button_2.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (view view) {
Setrequestedorientation (activityinfo.screen_orientation_portrait);
}
});
}
Attached Demo:
http://files.cnblogs.com/files/fyz666/pro2.apk
Android Screen Orientation switch