android - How to make application run portrait in phone and landscape on tablets -
hi looking learn these can give more layouts , ui exp of application. want app must run in portrait mode in case of phone can set in androidmanifest.xml
<activity android:name=".splashactivity" android:label="@string/title_activity_splash" android:screenorientation="portrait"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity>
but keep phones , tablet. if way of course layout won't on 7 , 10 inch screens.
question
how set such app run in portrait mode in mobile phones , landscape mode on 7 , 10 inch screens.
thanks in advance.
create new file named bools.xml in values
folder below:
<?xml version="1.0" encoding="utf-8"?> <resources> <item type="bool" name="islargelayout">false</item> </resources>
create file in values-large
folder named bools.xml below:
<?xml version="1.0" encoding="utf-8"?> <resources> <item type="bool" name="islargelayout">true</item> </resources>
now in activity before calling setcontentview
resource , based on value decide port or land orientation:
boolean islargelayout = getresources().getboolean(r.bool.islargelayout); if(islargelayout) { // tablet mode setrequestedorientation(activityinfo.screen_orientation_landscape); } else { // handset mode setrequestedorientation(activityinfo.screen_orientation_portrait); }
Comments
Post a Comment