The Orientation is change two types.
First-> you set the screen orientation in AndroidMenifest.xml .
<activity
android:name="com.example.androidbegnner.MainActivity"
android:label="@string/app_name"
android:screenOrientation="landscape" // shows you screen in landscape
>
<activity
android:name="com.example.androidbegnner.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" // shows you screen in portrait
>
Second->you change Orientation programmatic show below example.
My activity......................................................................................................
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Window;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// setRequestedOrientation(ActivityInfo.
SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
setContentView(R.layout.activity_main);
}
}
0 comments