As we are done with our first 'Hello World' program lets move a bit further and talk about LinearLayout in Android.
There are two methods for defining the position of components(Button, EditText, ....) in Android
Method 1: By directly embedding the components into the java code as we did in java.
Method 2: By using the xml file to define the layout.
The 2nd method defined above is mostly used. This method separates the designing part with the coding one. So code management becomes easier. Hence, we'll be discussing much about the xml layout files henceforth.
Note : A most important thing that i should have told earlier. Do not in any way try to play with the R.java file generated in the project. This is a self generated file and represents all the resources in the project.
Coming back, as the name indicates all the components contained in the <Linearlayout>....</Linearlayout> would be arranged in an linear fashion.
Sample 1: android:orientation="vertical"
Output:
Sample 2: android:orientation="horizontal"
Output:
Sample 3: android:gravity="center"
Output:
Sample 4: android:gravity="right"
Output:
Sample 5: Layout within Layout
Output:
There are two methods for defining the position of components(Button, EditText, ....) in Android
Method 1: By directly embedding the components into the java code as we did in java.
Method 2: By using the xml file to define the layout.
The 2nd method defined above is mostly used. This method separates the designing part with the coding one. So code management becomes easier. Hence, we'll be discussing much about the xml layout files henceforth.
Note : A most important thing that i should have told earlier. Do not in any way try to play with the R.java file generated in the project. This is a self generated file and represents all the resources in the project.
Coming back, as the name indicates all the components contained in the <Linearlayout>....</Linearlayout> would be arranged in an linear fashion.
Sample 1: android:orientation="vertical"
Output:
Sample 2: android:orientation="horizontal"
Output:
Sample 3: android:gravity="center"
Output:
Sample 4: android:gravity="right"
Output:
Sample 5: Layout within Layout
Output:
No comments:
Post a Comment