android:先感知默认的朝向,然后应用朝向,固定它的朝向

package com.chnfuture.scaletypeimageview;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity{
	
	private Button minButn;
	int orientation;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		TextView tv = new TextView(this);
		tv.setText("hello");
		setContentView(tv);
		Log.i("orientation", "onCreate");
		
		Display display = getWindowManager().getDefaultDisplay();
		int width = display.getWidth();
		int height = display.getHeight();
		if (width > height) {
			orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
		} else {
			orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
		}
		Log.i("orientation", orientation+"");
	}
	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		// TODO Auto-generated method stub
		super.onConfigurationChanged(newConfig);
		this.setRequestedOrientation(orientation);
		Log.i("orientation", "onConfigurationChanged");
	}
	
	
	
}

  

posted @ 2012-08-03 17:30  ligang305  阅读(220)  评论(0编辑  收藏  举报