1. 程式人生 > >Android 設置橫屏或豎屏

Android 設置橫屏或豎屏

new div highlight ati oid @override ride cape over

private void init() {

     Button landButton = (Button) findViewById(R.id.landbutton);
    landButton.setOnClickListener(new ClickListenerlandButton());

    Button VButton = (Button) findViewById(R.id.Vbutton);
    VButton.setOnClickListener(new ClickListenerVButton());
}

private class ClickListenerlandButton implements OnClickListener {
    @Override
    public void onClick(View v) {
        landScreen();
    }

}
private  void landScreen()
{
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//橫屏

}
private class ClickListenerVButton implements OnClickListener {
    @Override
    public void onClick(View v) {
        VScreen();
    }

}
private  void VScreen()
{
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//豎屏

}

  

Android 設置橫屏或豎屏