One of the most common causes of device fragmentation is different screen sizes on mobile devices. Disparate screen sizes require different resources, and usually, it is not advisable to include unused resources in the distribution JAR file. Imagine the scenario in which your application has a fixed-size splash-screen image, and you want to include only the correct-size image with each configuration. There are two different methodologies that you can use to manage this problem using NetBeans Mobility Pack. Which method you should use depends on whether you are working with an existing project structure or have the freedom to handle the problem in any way that suits you. Using Different Resource LocationsOne technique is to create size-specific resource JAR files or folders that contain identically named resources. For example, you might have a directory structure like this: /res/small/splashScreen.png /res/medium/splashScreen.png /res/large/splashScreen.png Your source code would read simply: Image splashScreen = Image.createImage("splashScreen.png"); Then you can modify the Libraries & Resource panel such that each configuration imports only the correct resource file for the screen size on the devices to which it will be deployed. Using Configuration-Specific Code Blocks and the Filtering PanelAn alternative solution is to have distinctly named resources all contained under the project's source root. So you might have a directory structure something like this: /src/res/splashScreenSmall.png /src/res/splashScreenMedium.png /src/res/splashScreenLarge.png Then you would need three configuration-specific code blocks in your source code for the create statement, meaning that your source would look like the code in Figure 14-5. Figure 14-5. Example of configuration-specific code blocks in the Source EditorFinally, the Filtering Sources panel would be modified for each configuration such that only the used resource would be selected in each. Both of these solutions result in similar-size application JAR files that include only the used resources. Therefore, it is up to you which technique is best suited to your project structures. |