Showing posts with label layout. Show all posts
Showing posts with label layout. Show all posts

Saturday, November 13, 2010

Getting the alignment right.

As you could see from the previous post, things were not really in place.  I was on that task and I got a good help from the Android Forum.  He had added a "a bottom margin of 62dip" for the RadioGroup and things were much better. 

Incidentally, DIP is "density-independent pixels"  Its an easy way of specifying the size independently of the screen specifics but the OS will keep the widgets in same physical size.

http://developer.android.com/guide/practices/screens_support.html#density-independence
http://stackoverflow.com/questions/2025282/difference-of-px-dp-dip-and-sp-in-android

coming back, further to his sugessions, I started modifying and my xml and the current state is like this.

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
   
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="10">
           
          <RadioGroup android:layout_width="wrap_content" android:orientation="vertical" android:layout_height="fill_parent" android:layout_marginBottom="50dip" android:layout_marginTop="5dip" android:layout_marginRight="10dip">
                  <RadioButton android:id="@+id/radioAmount" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:tag="Amount" android:layout_weight="1"/>
                  <RadioButton android:id="@+id/radioInt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:tag="Int" android:layout_weight="1"/>
                  <RadioButton android:id="@+id/radioTerm" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:tag="Term" android:layout_weight="1"/>
                  <RadioButton android:id="@+id/radioEMI" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" android:tag="EMI" android:layout_weight="1"/>
                </RadioGroup>
           
           
          <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="fill_parent">
                         
                    <TextView android:id="@+id/labelAmount" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="theAmount" android:textSize="22dip"/>
                    <EditText android:id="@+id/entryAmount" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/labelAmount" android:inputType="numberDecimal" android:layout_marginBottom="5dip" android:textSize="22dip"/>     
                             
                    <TextView android:id="@+id/labelInt" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/entryAmount" android:text="The Interest:" android:textSize="20dip"/>
                    <EditText android:id="@+id/entryInt" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/labelInt" android:inputType="numberDecimal" android:layout_marginBottom="5dip" android:textSize="22dip"/>
                       
                    <TextView android:id="@+id/labelTerm" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/entryInt" android:text="The Term (months):" android:textSize="20dip"/>
                    <EditText android:id="@+id/entryTerm" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/labelTerm" android:inputType="numberDecimal" android:layout_marginBottom="5dip" android:textSize="22dip"/>
                       
                    <TextView android:id="@+id/labelEMI" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/entryTerm" android:text="theEMI" android:textSize="20dip"/>    
                    <EditText android:id="@+id/entryEMI" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/labelEMI" android:inputType="numberDecimal" android:textSize="20dip"/>
                          
                </RelativeLayout>
         
        </LinearLayout>
         
    <LinearLayout
        android:layout_weight="1" android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_gravity="center">
         
        <Button
            android:id="@+id/buttonCalculate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:width="200dip"
            android:height="20dip"
            android:text="Calculate"
            android:lines="1"
            android:gravity="center_vertical|center_horizontal" android:layout_gravity="center"/>         
         
    </LinearLayout>
     
</LinearLayout>



The EMI Calculator with the above Layout.



But there was a problem.  If it runs on a smaller screen, either things will be squeezed to fit or some of the items will not be accessible.  So now I am thinking of adding a scrollbar so that (I am expecting) the said problem will not happen.

I got some clue from the following link.
http://www.androidpeople.com/android-horizontalscrollview-example/


So till I figure something out, bye...