In the previous post we worked on Simple Linear Layout. We saw that there can be two orientation Vertical and Horizontal in which Views/Widgets can be arranged.
In this post we will use both the Orientations Vertical and Horizontal to nest the Layout.
By nesting the Layout we can make better and finer GUI.
We want following Layout
Name: EditText
Password: EditText
Login Button Cancel Button
The parent Layout has Vertical Orientation and Children Layouts have Horizontal Orientation.
main.xml
<!-- Parent Layout With Vertical Orientation -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="30dp">
<!-- 1st Child Layout (Nested In Parent Layout) with Horizontal Orientation -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewName"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="25dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Name" />
<EditText
android:id="@+id/editText2"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10" />
</LinearLayout>
<!-- 2nd Child Layout (Nested In Parent Layout) with Horizontal Orientation -->
<LinearLayout mlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewPassword"
b
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="25dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Password" />
<EditText
android:id="@+id/editTextPassword"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<!-- 3rd Child Layout (Nested In Parent Layout) with Horizontal Orientation -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button1"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Login" />
<Button
android:id="@+id/button2"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Cancel " />
</LinearLayout>
</LinearLayout>
In this post we will use both the Orientations Vertical and Horizontal to nest the Layout.
By nesting the Layout we can make better and finer GUI.
We want following Layout
Name: EditText
Password: EditText
Login Button Cancel Button
The parent Layout has Vertical Orientation and Children Layouts have Horizontal Orientation.
main.xml
<!-- Parent Layout With Vertical Orientation -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="30dp">
<!-- 1st Child Layout (Nested In Parent Layout) with Horizontal Orientation -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewName"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="25dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Name" />
<EditText
android:id="@+id/editText2"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10" />
</LinearLayout>
<!-- 2nd Child Layout (Nested In Parent Layout) with Horizontal Orientation -->
<LinearLayout mlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewPassword"
b
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="25dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Password" />
<EditText
android:id="@+id/editTextPassword"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<!-- 3rd Child Layout (Nested In Parent Layout) with Horizontal Orientation -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button1"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Login" />
<Button
android:id="@+id/button2"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Cancel " />
</LinearLayout>
</LinearLayout>
Thing to Remember here is
android:layout_weight the attribute specifies how much weight/space the view will have or acquire on parent.
In Above example
android:layout_weight is 1 in both button so they have acquired equal space
Now give 1 weight to first button and 2 to second button.
See the effect
s
Customizing Toast In Android
Showing Toast for Longer Time
Customizing the Display Time of Toast
Using TimePickerDialog and DatePickerDialog In android
Animating A Button In Android
Populating ListView With DataBase
Customizing Checkboxes In Android
Increasin Size of Checkboxes
Android ProgressBar
Designing For Different Screen Sizes
Handling Keyboard Events
Understanding Android Manifest File of your android app
Working with Linear Layout (With Example)
Nested Linear Layout (With Example)
Table Layout
Frame Layout(With Example)
Absolute Layout
Grid Layout
Activity Life Cycle
Starting Activity For Result
Sending Data from One Activity to Other in Android
Returning Result from Activity
Using CheckBoxes in Android
Using AutoCompleteTextView in Android
Grid View
Customizing the Display Time of Toast
Customizing Toast At Runtime
Adding Image in Toast
Showing Toast for Longer Time
Adding Radio Buttons In Dialog
Adding Check Boxes In Dialog
Creating Customized Dialogs in Android
Adding EditText in Dialog
Creating Dialog To Collect User Input
How To Receive SMS
Accessing Inbox In Android
Creating Context Menu In Android
How to Forward an Incoming Call In Android
CALL States In Android
How To Vibrate The Android Phone
Sending Email In Android
Opening a webpage In Browser
How to Access PhoneBook In Android
Prompt User Input with an AlertDialog
Reading and Writing files to SD Card
Creating Table In Android
Inserting, Deleting and Updating Records In Table in Android
How to Create DataBase in Android
Accessing Inbox In Android
Now give 1 weight to first button and 2 to second button.
See the effect
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button1"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Login" />
<Button
android:id="@+id/button2"
android:layout_weight="2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Cancel " />
</LinearLayout>
s
Advance Android Topics
Customizing Toast In Android
Showing Toast for Longer Time
Customizing the Display Time of Toast
Using TimePickerDialog and DatePickerDialog In android
Animating A Button In Android
Populating ListView With DataBase
Customizing Checkboxes In Android
Increasin Size of Checkboxes
Android ProgressBar
Designing For Different Screen Sizes
Handling Keyboard Events
More Android Topics:
Android : Introduction
Eclipse Setup for Android Development
Configuring Eclipse for Android DevelopmentBegging With Android
Creating Your First Android ProjectUnderstanding Android Manifest File of your android app
Working With Layouts
Understanding Layouts in AndroidWorking with Linear Layout (With Example)
Nested Linear Layout (With Example)
Table Layout
Frame Layout(With Example)
Absolute Layout
Grid Layout
Activity
Activity In AndroidActivity Life Cycle
Starting Activity For Result
Sending Data from One Activity to Other in Android
Returning Result from Activity
Working With Views
Using Buttons and EditText in AndroidUsing CheckBoxes in Android
Using AutoCompleteTextView in Android
Grid View
Toast
Customizing Toast In AndroidCustomizing the Display Time of Toast
Customizing Toast At Runtime
Adding Image in Toast
Showing Toast for Longer Time
Dialogs In Android
Working With Alert DialogAdding Radio Buttons In Dialog
Adding Check Boxes In Dialog
Creating Customized Dialogs in Android
Adding EditText in Dialog
Creating Dialog To Collect User Input
DatePicker and TimePickerDialog
Using TimePickerDialog and DatePickerDialog In androidWorking With SMS
How to Send SMS in AndroidHow To Receive SMS
Accessing Inbox In Android
ListView:
Populating ListView With DataBaseMenus In Android
Creating Option MenuCreating Context Menu In Android
TelephonyManager
Using Telephony Manager In AndroidWorking With Incoming Calls
How To Handle Incoming Calls in AndroidHow to Forward an Incoming Call In Android
CALL States In Android
Miscellaneous
Notifications In AndroidHow To Vibrate The Android Phone
Sending Email In Android
Opening a webpage In Browser
How to Access PhoneBook In Android
Prompt User Input with an AlertDialog
Storage: Storing Data In Android
Shared Prefferences In Android
SharedPreferences In AndroidFiles: File Handling In Android
Reading and Writing files to Internal StoarageReading and Writing files to SD Card
DataBase : Working With Database
Working With Database in AndroidCreating Table In Android
Inserting, Deleting and Updating Records In Table in Android
How to Create DataBase in Android
Accessing Inbox In Android
Thanks for the clean example Man... Even this http://www.compiletimeerror.com/2013/06/android-linearlayout-example.html might help.. Have a look..
ReplyDeleteHowdy! Ι coulⅾ hɑve sworn I?ѵe visited tһis site before but after
ReplyDeletelooking at a fеw ᧐f tһе articles I realized іt?s new
to me. Anyhow, I?m definitely delighted I foᥙnd it ɑnd I?ll be bookmarking іt ɑnd checking back often!
Неllo! I know this iѕ kind of off topic Ьut I was wondering if yߋu knew
ReplyDeletewheгe Ι could get a captcha plugin for my comment foгm?
I'm սsing the same blog platform ɑѕ yours and I'm having difficulty finding ߋne?
Thаnks a lot!
casino online
ReplyDeletecasino online
online casino
casinos online
casinos online
This is very interesting, You're a very skilled blogger.
ReplyDeleteI have joined your rss feed and look forward to seeking more of your fantastic post.
Also, I have shared your website in my social networks!
I just could not leave your web site prior to suggesting that I
ReplyDeletereally enjoyed the standard information an individual provide to your visitors?
Is going to be back frequently to check out new posts
Me ha llamado la atencion demasiado la noticia, ciertamente buena, muchas gracias por la advertencia,
ReplyDeletebastante aclarativa. Continuo investigando por
la web a ver mas cosillas informativas, muchas gracias de nuevo.
Hurrah, that's what I was looking for, what a data! present here at this
ReplyDeletewebsite, thanks admin of this site.
It is appropriate time to make a few plans for the future and
ReplyDeleteit's time to be happy. I've read this submit
and if I may just I wish to counsel you few interesting issues
or tips. Perhaps you could write subsequent articles relating to
this article. I want to learn even more issues approximately it!