Hi Friends,
Check Android Apps on Google Play
https://play.google.com/store/apps/developer?id=Metro%20App%20Solution&hl=en
Here i am going to show you how to stop/disable screen rotation/orientation of your application in Android while Auto Rotation is enabled in your mobile.
For this just you have to made changes in Activity tag of your Application Manifest :
<activity
android:name="in.androiddevelopmentanddiscussion.disablescreenrotationexample.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
If you want you application activity in Landscape then just change orientation "portrait" to "landscape".
That's it Enjoy Coding ............ :)
Example:
Landscape Screen
Portrait Screen
Code:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
MainActivity.java
package in.androiddevelopmentanddiscussion.disablescreenrotationexample;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.androiddevelopmentanddiscussion.disablescreenrotationexample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="in.androiddevelopmentanddiscussion.disablescreenrotationexample.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"> (Change it Accordingly)
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Download full project from here
Check Android Apps on Google Play
https://play.google.com/store/apps/developer?id=Metro%20App%20Solution&hl=en
No comments:
Post a Comment