Wednesday, May 8, 2013

Nested Linear Layout In Android

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>


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




 <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 Development

          Begging With Android

                     Creating Your First Android Project
                     Understanding Android Manifest File of your android app


         Working With Layouts

                      Understanding Layouts in Android
                          Working with Linear Layout (With Example)
                                Nested Linear Layout (With Example)
                          Table Layout
                          Frame Layout(With Example)
                         Absolute Layout
                         Grid Layout


       Activity

                     Activity In Android
                     Activity 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 Android 
                     Using CheckBoxes in Android 
                     Using AutoCompleteTextView in Android
                     Grid View

       Toast

                     Customizing Toast In Android
                     Customizing the Display Time of Toast
                     Customizing Toast At Runtime
                     Adding Image in Toast
                     Showing Toast for Longer Time

     Dialogs In Android

                     Working With Alert Dialog
                     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

                 DatePicker and TimePickerDialog

                              Using TimePickerDialog and DatePickerDialog In android

    Working With SMS

                  How to Send SMS in Android
                  How To Receive SMS
                  Accessing Inbox In Android

    ListView:

               Populating ListView With DataBase

      Menus In Android

                    Creating Option Menu
                    Creating Context Menu In Android

      TelephonyManager

                    Using Telephony Manager In Android

     Working With Incoming Calls

                    How To Handle Incoming Calls in Android
                    How to Forward an Incoming Call In Android
                   CALL States In Android
 

    Miscellaneous

                   Notifications 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

   Storage:  Storing Data In Android


               Shared Prefferences  In Android

                             SharedPreferences In Android

               Files: File Handling In Android

                              Reading and Writing files to Internal Stoarage
                              Reading and Writing files to SD Card 
                           

                DataBase : Working With Database

                             Working With Database in Android
                             Creating Table In Android
                             Inserting, Deleting and Updating Records In Table in Android
                             How to Create DataBase in Android
                             Accessing Inbox In Android

     Animation In Android:

                  Animating A Button In Android





9 comments:

  1. Howdy! Ι coulⅾ hɑve sworn I?ѵe visited tһis site before but after
    looking 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!

    ReplyDelete
  2. Неllo! I know this iѕ kind of off topic Ьut I was wondering if yߋu knew
    wheг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!

    ReplyDelete
  3. casino online
    casino online
    online casino
    casinos online
    casinos online

    ReplyDelete
  4. This is very interesting, You're a very skilled blogger.
    I 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!

    ReplyDelete
  5. I just could not leave your web site prior to suggesting that I
    really enjoyed the standard information an individual provide to your visitors?
    Is going to be back frequently to check out new posts

    ReplyDelete
  6. Me ha llamado la atencion demasiado la noticia, ciertamente buena, muchas gracias por la advertencia,
    bastante aclarativa. Continuo investigando por
    la web a ver mas cosillas informativas, muchas gracias de nuevo.

    ReplyDelete
  7. Hurrah, that's what I was looking for, what a data! present here at this
    website, thanks admin of this site.

    ReplyDelete
  8. It is appropriate time to make a few plans for the future and
    it'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!

    ReplyDelete