Saturday, June 11, 2011

More About Android Resources and Manipulation

Android Layout Tutorial 04

First of all I like to know about past layout editing posts are worthy or not, any way I found a easy way to generate layout xml even with complex positionings of object. Check below link just create your layout easily.

                                                                  http://www.droiddraw.org/

OR even you can download the binary also -  (Mac OS X, Windows, Linux)

This post mainly focus about how add resources to the project and how those use, manipulate in layouts. Just step to pool :)

OK, here I want to focus your attention for "res" folder, you can see there are set of files call "drawable-hdpi" , "drawable-ldpi","drawable-mdpi" those files basically for add image resources for your application. BUT WHY 3 FOLDERS?
These are for images of various resolutions, just open folders, there are one sample file in both three folder. Check the sizes of each file, even those three had same name ("icon.png") their sizes are different. So there is meaning with those folder names.

  • drawable-hdpi -  higher dot per inch(hdpi)
  • drawable-ldpi - Lover dot per inch(ldpi)
  • drawable-mdpi - Mid dot per inch(mdpi )

The hdpi qualifier indicates that the resources in that directory are for devices with a high-density screen. While the images in each drawable directory are sized for a specific screen density, the filenames are the same. This way, the resource ID that you use to reference the icon.png image is always the same, but Android selects the version of that drawable that best matches the current device configuration.

EASY WAY TO CREATE IMAGES FOR YOUR APPLICATION 
When you create a image, icon you should provide both three resolution images for better application flexibility to work on different resolution environment. Now by "Android Asset Studio"  provide facility to get generate icons and images with both three resolutions . 
Click Here > Android Asset Studio
It provide functionalities to create what you want in easy manner, otherwise you may have to deal with photoshop to get done those. 

Even in this service provide selected and unselected views also. that will help you a lot when going to develop professional level forms :)

Lets add some images from drawable files. 

open the Layout file and by using "Graphical layout" view add " imageView " to the interface and open the xml view. Got to the " imageView " tags and change the source as this image.


Now run you application, it shows added image in the screen. you can add sound files  for button click, actions etc. but we will discuss those in later tutorials, because those require bit knowledge of java programming and specially about threads. Let me to make prepare you easy to that step. 


Thank You All


Next post :
About Android Application File Structure

                                                                                                                                                                                     By MIthila Karunarathna

No comments:

Post a Comment