Close
Topic : Using Android Resources - Advantages | Default Resources | Alternative Resources



Android Resources: infobrother

Android Resources:

Android Application is Not all about source code, there are many other files to make an Android application. Apart from coding the application, we have various other files to care about, like some static content that our code use, such as Application Layout, it's color, some videos and audio files, animation and instruction, bitmaps and more. These are files are non-source code files and referred to as Resources and are compiled along with the source code to build an application.



Source code + Resources = .apk file: infobrother

  • Advantages:

    Android Resources Provide several Advantages to an Android Application.
    » Code Separation: Resources Help us to create different location for Non-source code files. We can Save all our images in one folder, videos in another folder, menus in another folder and so on.
    » Target Multiple Devices: Resources help us to target multiple devices without changing of code.
    » Compile-time Checking: Resources help to catch error and mistakes at compile time. Resources are static and compiled into the application. and it allow us to check our application at compile time. and its easy to check the application and remove error at compile time.



Organize Resource in Visual Studio:

Default Android Resources

In Visual Studio, Application resources are organized according to their type into these subdirectories.
» Images files goes into the Drawable Directory.
» XML files that define a User Interface Layout goes into the Layout Directory.
» XML Files that contain Simple Values, such as String, integers and color goes into the Values directory.

These Resources are Known as Default Resources and are used by all devices unless a more specific match is specified.



Default Resources:

Default Resources are Items that are not specific to any particular device, therefore these resources are default choice by Android operating system if no more specific resources can be found. These resources are the most common type of resource to create and are organized into sub-directories of the Resources directory according to their resource type.



Below table provide the complete list of resources.


Resource typeDirectoryDescription
animatorResources\animator\It's an XML file, that define property animations. The property animations are powerful and flexible way to describe animations.
animResources\anim\It's an XML fle that describe Tween animations. Tween animations are a series of animation instruction to perform transformations on the contents of a view object.
colorResources\color\It's an XML files that describe a state list of color. To Understand color state lists, consider a Button. It have different states such as pressed or disables. The button is blue, so it may change its color to red when user press it.
drawableResources\drawable\In this directory, we can save image files of any type Or XML files that are compiled into bitmaps, state lists, shapes or animation drawable.
layoutResources\layout\It's an XML file that define a user interface layout.
menuResources\menu\It's an XML file that define application menus, such as Option menu, context menu, or sub menu.
rawResources\raw\These are Arbitrary files. these files are compiled into an android application in a binary format.
valuesResources\values\It's an XML file that contain simple values, such as string, integers, color etc.
xmlResources\xml\These are Arbitrary XML files, and we read these files at runtime. We can save various configuration files here which will be used at run time.


Alternative Resources:

Alternative Resources Provide support to specific device configuration. For Example, we should include alternative drawable resources like images for different screen resolution and alternative string resources for different language. At run time, Android detect the current device configuration and loads the appropriate resources for our application.



How Android Determines what Resources to use?

It is possible that An android Application will contain many resources. So, How Android will select the resources for an application when it runs on a device?

Take these following example to understand how Android Select the Resources.
» If the Device Orientation is Portrait, Then Android will ignore all Landscape resources directories.
» If a Resource directory contains a Qualifier that is not supported by the device, Android will ignore that resource directory.



















I Tried my Best to Provide you complete Information regarding this topic in very easy and conceptual way. but still if you have any Problem to understand this topic, or do you have any Questions, Feel Free to Ask Question. i'll do my best to Provide you what you need.

Sardar Omar.
InfoBrother





WRITE FOR INFOBROTHER

Advertising






Advertisement