

package com.exercise.AndroidOrientation;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class AndroidOrientationActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        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) {
    // TODO Auto-generated method stub
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
   }});
        
        buttonSetLandscape.setOnClickListener(new Button.OnClickListener(){
   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
   }});
    }
}
Related:
- Activity will be re-started when screen orientation changed
No comments:
Post a Comment