Android Screen Orientation switch

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.