androidManifest.xml
<activity
android:name="com.qfa.gcm.MainActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize|keyboardHidden"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
===========================================================
MainActivity.java
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_LONG).show();
imageView.setScaleType(ScaleType.FIT_CENTER);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_LONG).show();
imageView.setScaleType(ScaleType.FIT_XY);
}
}
===============================================================
<activity
android:name="com.qfa.gcm.MainActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize|keyboardHidden"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
===========================================================
MainActivity.java
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_LONG).show();
imageView.setScaleType(ScaleType.FIT_CENTER);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_LONG).show();
imageView.setScaleType(ScaleType.FIT_XY);
}
}
===============================================================
No comments:
Post a Comment