문제

I have created an android app which works fine on phone (portrait) and on 10 inch tablet (Landscape). But problem is with 7 inch tablet.It opens in portrait mode but uses UI of tablet..so UI is looking totally distracted. I want to open app in 7 inch in landscape mode..how could it be possible through code...? Any suggestions would be appreciated,. Thanks in advance.

Manifest file declaration ---

 <activity
        android:name=".MainActivityTheme"
        android:label="@string/app_name"
        android:screenOrientation="nosensor" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
도움이 되었습니까?

해결책

Create a folder in /res directory as layout-xlarge-land and another one as layout-large-land , keep the same file in both the folders and you are done.

These are recommended folders where you should put your files , this is not the complete list but it can be appended with many ,

layout-xlarge-land  landscape for 10 inch tablets and 10.1
layout-xlarge-port portrait for 10 inch tablets and 10.1
layout-large-land landscape for 7 inch tablets and 7.1
layout-large-port portrait for 7 inch tablets and 7.1

move your layout file between these folders to properly use it.

다른 팁

I'd better leave a comment, but have not got enough reputation yet.
You should define some layout in layout-land directory, not only layout-land-large.
Looks like your tablet has non-large screen, and there is no layout for non-large landscape mode.

Finally, I got my answer. I changed my manifest file...like

  <activity
        android:name=".MainActivityTheme"
        android:label="@string/app_name"
        android:configChanges="keyboardHidden|screenSize|orientation">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

and dynamically changed orientation mode... like

if(isLargeScreen(this))
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
else
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

And moved all layout files in layout-large folder instead of layout-large-land. Thank you guys for help.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top