0

I have a problem in application, when I have a landscape mode application for tablet and small devices. I have put all the layout files in layout-land and layout-sw600dp-land folder. I have defined screen orientation in manifest file also. When I explore application, keeping mobile portrait I found an error of ResourceNotFoundException. How can I solve this problem?. Hoping for favorable answer.

Following is my menifest file implementation

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ui.MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="landscape" >
        </activity>
        <activity
            android:name=".ui.ForgotPassword"
            android:screenOrientation="landscape" />
        <activity
            android:name=".ui.LoginFragment"
            android:screenOrientation="landscape" />
        <activity
            android:name=".ui.Lending"
            android:screenOrientation="landscape" />
        <activity
            android:name=".ui.SavedTakeOff"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="landscape" />
        <activity
            android:name=".ui.ItemsFragment"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="landscape" />

4 Answers4

1

if you are following multiple layout support it is not limited to just land and port mode which you already know. but in order to portrait mode you need to keep your file in default layout folder.

MyProject/
res/
    layout/              # default (portrait)
        main.xml
    layout-land/         # landscape
        main.xml
    layout-large/        # large (portrait)
        main.xml
    layout-large-land/   # large landscape
        main.xml
CodingRat
  • 1,934
  • 3
  • 23
  • 43
  • these qualifiers are deprecated – Vivek Mishra Jan 04 '16 at 05:58
  • @VivekMishra I followed same structure for my landscape application as you posted above. But while exploring application sometime I face the issue of design change. It seems that sometime application bind layout from "layout" folder instead of "layout-land" folder. –  Jan 04 '16 at 06:09
  • I have not posted that . I am saying that now you should use sw notation to create folders for different resolutions layout. And double check your layouts and manifest for orientation and layout – Vivek Mishra Jan 04 '16 at 06:12
1

This is because when your device is in portrait Mode and you try to open the application it by default try to load resources of portrait mode then later it will change the orientation to Landscape(based on your manifest configuration) So you can just add a default layout of launcher screen on portrait mode this will solve your resource not Found exception and application still be loaded in Landscape mode.

Pratik Goyal
  • 294
  • 1
  • 9
  • I put all landscape layout in default layout folder as per your suggestion. But while exploring application sometime I face the issue of design change. It seems that sometime application bind layout from "layout" folder instead of "layout-land" folder. –  Jan 04 '16 at 06:14
  • 1
    No, no need to put all the layouts in the default layout folder, Just add layout of Launcher in the Layout folder in your case .SplashScreenActivity. Even if this does not work add Configuration change listener and post details to help us debug the issue. – Pratik Goyal Jan 04 '16 at 07:42
0

Just delete your R.java. then clean and rebuild your project.

Akhil Jayakumar
  • 2,262
  • 14
  • 25
0

Its simple i you use this class.you call this class and check its mobile or tablet

public class Utils {
public static void CopyStream(InputStream is, OutputStream os)
{
    final int buffer_size=1024;
    try
    {
        byte[] bytes=new byte[buffer_size];
        for(;;)
        {
          int count=is.read(bytes, 0, buffer_size);
          if(count==-1)
              break;
          os.write(bytes, 0, count);
        }
    }
    catch(Exception ex){}
}

public static boolean isTablet(Activity activity) {
    return (activity.getResources().getConfiguration().screenLayout
        & Configuration.SCREENLAYOUT_SIZE_MASK)
        >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}}

simply you call In Activity you call this its will check mobile or tablet

 if (!Utils.isTablet(this))
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Binesh Kumar
  • 2,763
  • 1
  • 16
  • 23