Saturday, June 4, 2011

Android Layout Editing and Resource Handling

Android Layout Tutorial 01


Hi Everyone.... 


In my posts I always trying to explain things with image illustrations, because I personally believe its better communication method than texts. if there any comments please let me know, I appreciate it very much. 


With this third post I'm going to show you how arrange component on the layout of Android UI. If you have came across past blog posts you may have folder structure with "Layout" folder. within that you can see "main.xml " or any customized xml file. This xml file have the all information how content arrange, align, sized on the your application user interface. Double click on your layout xml file, then it will open  in the tabular format with two sub tabs call main.xml (anyname.xml) and Graphical Layout. First of all lets see some basic stuff.
Graphical Layout : shows how your XML arrangements appear actually on the phone. You can change the positions of the component from here also. 

Just select "main.xml" tab to check out the xml content.
            Ok, Do you remember that wording "HelloWorld" on the screen ? 
            Can you find that content on the xml? 

This content not directly have in the xml but it is in there, in your xml you can see

           android:text="@string/hello"



How this line paste that phrase on the view (Hello World........)? 

I want your attention now, contents of the view coming from "Android Resource". Because these content should be accessible by codes at the Actions, don't get it serious we discus later about actions an other stuffs :). This Resources also store as in xml format and lets see how we can manipulate resources. 

                   Goto-> Folder "values" > "strings.xml"

Now double click and open it as usual, you can see "Android Resource (Default)" window. Now it shows list of elements but in front of all we can see (String) specification have added. these all elements are Strings (Don't you kno what is String in programming ? check it from here)
Just click on that "hello" string element on left hand side you can see the value of that element, this "hello" element contain that "hello world ....." 
phrase. If you want to change it just change that words and check the interface, then you will realize what it is exactly. BUT DON'T CHANGE THE NAME OF STRING, if you change the name you have to change ti at the Layout xml also. because it now state as 
 android:text="@string/hello" (hello is the name of the string)




Did you experience that ? This is just easy step to make you aware how value passing to layout xml. Lets add our own string with saying what we want :)


Add new String element to Android resources


this is very easy step, just click add button and it quickly add new empty string in to element list.
just click on it and change the name and content string as what you want. (String name should be unique from other string names)


Now save or (Ctrl+s)  you successfully added the new string resource, then go to Layout xml ("main.xml"), edit that xml string name in to your new string variable name and check out the interface.
        android:text="@string/hello" => android:text="@string/YOUR NEW SRTING NAME"



TIP:- when you typing press Ctrl+Spacebar to get suggestions


You can add wordings directly to the lay out xml also. place your wording in between double quotation that defined string before
         android:text="@string/hello" => android:text="your texts paste here"
 as below image, you can copy before textView and can create new text view to test ti or can change on same place too. 


Did you got how work with layers and resources? If you learn or it benefits to u a bit I'm really happy. there are more to learn about Layout, so my next post also about how add new components and how arrange things on the layout.


Thank you all..............
If there any comment please let me know, Im really appreciated that,


Next post :
 How Content Arrange In Android Layout 

No comments:

Post a Comment