Lock Horizontal View
I want to lock horizontal view in my app, is it possible?
Help is high开发者_Python百科ly appreciated,
Thanks,
Use android:screenOrientation="landscape"
attribute for your activity.
add this code in your menifest...
<activity android:name=".activity"
android:configChanges="orientation" android:screenOrientation="portrait"></activity>
For new android Studio 3 and above you need to put these lines in AndroidManifest.xml code if you want to set the orientation to portrait
One thing this is sensor portrait, means both upside - downside will work.
But if you only want to put portrait for upside then, replace sensorPortrait to portrait
<activity
android:name=".MainActivity"
android:configChanges="orientation"
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity">
Same goes for only landscape too just one parameter change portrait to landscape
<activity
android:name=".MainActivity"
android:configChanges="orientation"
android:screenOrientation= "sensorLandscape"
tools:ignore="LockedOrientationActivity">
精彩评论