Android Layout Tutorial 02
Hi again ...
This is a short lesson to cover come surface things about layout editing ans component arrangements, even you interest to this you may self learn these things. Now you may familiar somewhat than before with the android file structure so not going to illustrate the files and places with images.
select "Graphical Layout" tab
You can see there are set of horizontal tabs in left side, expand the "Form Widgets" tab.
within that you can see components you are so familiar with programming stuff, text boxes, buttons, radio buttons, etc.
Just drag and drop those in to the black area (to screen), it just easy to place those in the screen, but just try to make arrange those as you want. it may bit difficult. Because those are only adding as horizontal or vertical layout only.
Just go to XML view of the file it just like this
----------------------------------------------------------------------------------
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:text="Button"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
----------------------------------------------------------------------------------LinearLayout - You can see all the content within this tag. default it has a Linear Layout, but if you want to change the lay out go to the layout tab and add what you prefer. BUT if you drag and drop a lay out available layout will not change, insted of that it will add new nested layout within LinearLayout.
It will just like this :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout android:layout_height="wrap_content" android:id="@+id/relativeLayout2" android:layout_width="match_parent"></RelativeLayout>
</LinearLayout>
Then within RelativeLayout area behave as relative but above act as linear. First add several components by just dragging and try to re arrange those components within linear lay out and feel how those can arrange and restrictions.
RelativeLayout : open the XML view and just remove "LinearLayout" and paste "RelativeLayout" for main tags and go to graphical view, you can see all the components overlapped each other and have set to left corner. Now add some component to the view and click on it and try to re arrange it, now you can see Green Grid shows on the screen and you can put the component in to that squires. see image below.
But still you may no able to put those components exactly to those positions, just try to do more experiments, you will get it, and always after a change just go and checkout the changes in the xml that may help you to understand terms used in xml.
Did you feel the different between those two?
OK DON'T GET IT SERIOUS, NOW YOU CAN ADD A BUTTON? OK THAT'S ENOUGH FOR NEXT LESSONS :)
What is layout_width And layout_height ?
simply as every one understand these are parameters about width and height. Yes, that is true. But available changes on this parameter is important. Add a Button and open the xml view of the layout. just focus to the strings equaled to the layouts. and press Ctrl + Spacebar. it shows available option. see below picture.

fill_parent - When we set this parameter it fill out the area according to the orientation, as an example when we set layout_width to fill_parent the element fill the area of the layout horizontally. If we set both layout_width, layout_height the area of the layout will fill-out from the component. see image below.
There are many options when layout editing, and experiment with various parameter adding to elements, you can easily do that by type " android: " and press CTRL + Spacebar. it is very difficult to illustrate all in the list.
In here I decided to mention about common error I have experience when running the application on virtual environment several time.
COMMON ERROR
ActivityManager: Warning: Activity not started, its current task has been brought to the front
It is not an error message, it is a warning. What the system is trying to tell you: The application on the device is the same as your application in Eclipse. And because the application is already running on the device, the system tells you that it is not going to kill and restart it, but bring the activity of your already running app into the foreground. This is pretty normal. ;-)
The warning will not continue if you edit your code and run it (because the app is then killed, reinstalled and started) or if you kill your process on the phone,
thank you all !
In next post I hope to discus how access resources from java code and adding about multiple views to application
fill_parent - When we set this parameter it fill out the area according to the orientation, as an example when we set layout_width to fill_parent the element fill the area of the layout horizontally. If we set both layout_width, layout_height the area of the layout will fill-out from the component. see image below.
There are many options when layout editing, and experiment with various parameter adding to elements, you can easily do that by type " android: " and press CTRL + Spacebar. it is very difficult to illustrate all in the list.
In here I decided to mention about common error I have experience when running the application on virtual environment several time.
COMMON ERROR
ActivityManager: Warning: Activity not started, its current task has been brought to the front
It is not an error message, it is a warning. What the system is trying to tell you: The application on the device is the same as your application in Eclipse. And because the application is already running on the device, the system tells you that it is not going to kill and restart it, but bring the activity of your already running app into the foreground. This is pretty normal. ;-)
The warning will not continue if you edit your code and run it (because the app is then killed, reinstalled and started) or if you kill your process on the phone,
thank you all !
In next post I hope to discus how access resources from java code and adding about multiple views to application
Multiple Layouts and Accessing Layout Components
No comments:
Post a Comment