Sunday, January 13, 2013

6. XML format for TextView and TextView parameters


1.Format of a TextView


       <TextView
                        android:id="@+id/textView1"
         />

        (Note: here the id of the TextView is "textView1".)

2.Important TextView Parameters



        android:layout_width="wrap_content" 
         (restrict the width of the layout to the content width, eg. width of text)

        android:layout_width="match_parent" 
        (extend the width to the parent width.eg.fill the screen width)

        android:layout_height="wrap_content"  
        (restrict the height of the layout to the content height. eg. height of text)

        android:layout_height="match_parent" 
        (extend the height to the parent height.eg. fill the screen height)

         android:text="@string/hello"
        (Display the text stored in the string named "hello". string is to be specified in the "strings.xml' file in the folder named "values" as follows)
        <string name="hello">your text here</string>

        android:hint="@string/hint1"
      (Display a text when the field is empty. Will automatically disappear when a text is shown. The hint  text is storedin a string called " hint1", string is to be specified in the "strings.xml' file in the
folder named "values as follows)
        <string name="hint1">your text here</string>
   
        android:textColor="@color/white" 
    (Apply the color stored in the string"white". string is to be specified in the "strings.xml in  the folder named   "values" as follows)
        <color name="white">#FFFFFF</color>

        android:textSize="15sp"
        (Display the size of the text in 15 scaled pixels, device independent)

        android:textStyle="bold"
         (Display the text as bold)

       android:typeface="serif"
         (Display the text in "serif" font)

        android:height="15sp"
        (Fix the height of the textview to 15sp)

        android:gravity="1"
        android:gravity="2"
    (If the gravity of item1 is "1" and of item2 is "2" both will occupy the area in the ratio 1:2, default gravity=0)

        android:gravity="center"
       (Display the text in the center of textview)

        android:background="@drawable/picture"
       (Set the background to an image called "picture.PNG", only PNG type image is supported. The image is to be stored in folder res>drawable-mdpi)

        android:layout_marginLeft="20dp"
       (A space of 20dp is kept on the left side)

        android:layout_marginRight="20dp"
        (A space of 20dp is kept on the right side)
       android:layout_marginBottom="20dp"
       (A space of 20dp is kept on the bottom)
       android:layout_marginBottom="20dp"
       (A space of 20dp is kept on the top)

        android:layout_alignParentTop="true"
        (Position the TextView at top of the parent. eg. top of screen)

        android:layout_alignParentBottom="true"
        (Position the TextView at bottom of the parent. eg. bottom of screen)

        android:layout_alignParentRight="true"
       (Position the TextView at right side of the parent. eg. right side of screen)

        android:layout_alignParentLeft="true"
       (Position the TextView at left side of the parent. eg. left side of screen)
      
        android:layout_alignBottom="@+id/button1"
        (Align the bottom of the TextView to button1)

        android:layout_toRightOf="@+id/button1"
        (Align the  TextView to the right of button1)

        android:layout_toLeftOf="@+id/button1"
        (Align the TextView to the left of button1)

        android:layout_centerHorizontal="true"
        (Position the TextView in Center Horizontal)

        android:layout_centerVertical="true"
       (Position the TextView in Center Vertical)

      see the Format of EditText and Imporatant EditText Parameters In NEXT CHAPTER

4 comments:

Please give your valuable comments so as to know whether this blog is useful to you.You can also write helpful Android Development Syntax or Shortcuts or Tips.