Showing posts with label Linear. Show all posts
Showing posts with label Linear. Show all posts

Saturday, 20 April 2013

Linear Layout and its major properties in android


[1] LinearLayout
  • LinearLayout is a view group that align all children in a single direction, vertically or horizontally. The default orientation is horizontal.
    In vertical LinearLayout,all children are stacked one after another,so a vertical list will only have one child per row,no matter how wide they are and a horizontal list will only be one row high. You can specify the layout direction with the android:orientation attribute or setOrientation() method.

    Gravity: which specifies the alignment of all the child elements(right, center,or left alignment) by calling setGravity() method or android:gravity  attribute.

    LinearLayout also supports assigning a weight to individual children with the android:layout_weight attribute. This attribute assigns an "importance" value to a view in terms of how much space is should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the parent view. Child views can specify a weight value, and then any remaining space in the view group is assigned to children in the proportion of their declared weight. Default weight is zero.
              
                  
                 




    Another important property of linear layout is Orientation.
    Orientation is either Horizontal or vertical.
    If Orientation is horizontal then it adds view in one row and if Orientation
    is vertical then it adds view in one column.
    Below xml is for horizontal orientation



    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/personinformation_txtvw_title1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="@string/title" />
     <TextView

                android:id="@+id/personinformation_txtvw_title2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="@string/title" />
     <TextView

                android:id="@+id/personinformation_txtvw_title3"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="@string/title" />


     </LinearLayout>


    For vertical orientation you have to just change orientation="Vertical" in the linear layout .
    Below xml is for Vertical orientation



    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/personinformation_txtvw_title1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="@string/title" />
     <TextView

                android:id="@+id/personinformation_txtvw_title2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="@string/title" />
     <TextView

                android:id="@+id/personinformation_txtvw_title3"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="@string/title" />


     </LinearLayout>



    There is another useful property of linear layout is layout:weight.
    It will assign the area of view.

    Hope this will clear the linear layout and you can use it friendly in your android application.







Thursday, 17 January 2013

Dynamically Relative Layout at Runtime in android

Relative Layout at Runtime in android.



              RelativeLayout relParent = new RelativeLayout(HomeScreen.this);
              RelativeLayout.LayoutParams rlparent = new RelativeLayout.LayoutParams(
                           RelativeLayout.LayoutParams.FILL_PARENT,
                           RelativeLayout.LayoutParams.FILL_PARENT);
              relParent.setLayoutParams(rlparent);

              RelativeLayout relTop = new RelativeLayout(HomeScreen.this);
              RelativeLayout.LayoutParams rlpTop = new RelativeLayout.LayoutParams(
                           RelativeLayout.LayoutParams.FILL_PARENT,
                           RelativeLayout.LayoutParams.WRAP_CONTENT);
              rlpTop.addRule(RelativeLayout.ALIGN_PARENT_TOP);

              RelativeLayout.LayoutParams rlpBottom = new RelativeLayout.LayoutParams(
                           RelativeLayout.LayoutParams.FILL_PARENT,
                           RelativeLayout.LayoutParams.WRAP_CONTENT);
              rlpBottom.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

              relTop.setLayoutParams(rlpTop);
              relBottom.setLayoutParams(rlpBottom);

              TextView txtTitle = new TextView(HomeScreen.this);
              RelativeLayout.LayoutParams relParam = new RelativeLayout.LayoutParams(
                           RelativeLayout.LayoutParams.WRAP_CONTENT,
                           RelativeLayout.LayoutParams.WRAP_CONTENT);

              relParam.addRule(RelativeLayout.CENTER_IN_PARENT);
              txtTitle.setText("HomeScreen");
              txtTitle.setLayoutParams(relParam);
              txtTitle.setTextColor(Color.BLUE);
              txtTitle.setTextSize(18);

              relTop.addView(txtTitle);

              relParent.addView(relTop);
              relParent.addView(relBottom);

              setContentView(relParent);


It does not require any layout.xml file becuase all gui is using code.
In Relative Layout , we use RelativeLayout.LayoutParams same way
In Linear Layout , we use LinearLayout.LayoutParams.

 Our new android application for EGreeting.Have a look to it. 

 The Greetings Android Application 



NovaRadix Android Application Development Team
NovaRadix Technology
WWW.NOVARADIX.COM

GradientDrawable in Android

A Drawable with a color gradient for buttons, backgrounds, etc.
It can be defined in an XML file with the <shape> element. For more information, see the guide to Drawable Resources.



<?xml version="1.0"encoding="utf-8"?>
<gradient
    android:angle="-90"
    android:endColor="#A71C1C"
    android:startColor="#7c0000"
    android:type="radial" />



Gradient is used in shape and it looks like this.

<?xml version="1.0"encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <gradient
        android:angle="90"
        android:endColor="#A71C1C"
        android:startColor="#7c0000" />

</shape> 

another example of shape drawable: 
 

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <stroke
        android:width="2dp"
        android:color="#FFFFFFFF" />

    <gradient
        android:angle="225"
        android:endColor="#DD2ECCFA"
        android:startColor="#DD000000" />

    <corners
        android:bottomLeftRadius="7dp"
        android:bottomRightRadius="7dp"
        android:topLeftRadius="7dp"
        android:topRightRadius="7dp" />

</shape>

Attributes Name and its meaning for gradient drawable in android :

android:type

There are 3 types of gradients, the default and the one for this question is "linear". The other 2 are "radial" and "sweep".

android:angle

Counter-clockwise rotation of the gradient, where 0 is | start color --> end color | (horizontally).

android:startColor

Color the gradient starts from, start is defined by the rotation.

android:endColor

Color the gradient ends with, end is defined by the rotation.

android:centerColor

There can also be a color in between the start and end color, if desired.

 We can use gradient in selector also.



<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true"><shape>
            <gradient android:angle="270" android:endColor="@color/button_pressed" android:startColor="@color/button_pressed" />

            <stroke android:width="3dp" android:color="@color/button_pressed" />

            <corners android:radius="3dp" />

            <padding android:bottom="5dp" android:left="5dp" android:right="5dp" android:top="5dp" />
        </shape></item>
    <item android:state_focused="true"><shape>
            <gradient android:angle="270" android:endColor="@color/info_normal" android:startColor="@color/info_normal" />

            <stroke android:width="3dp" android:color="@color/info_normal" />

            <corners android:radius="3dp" />

            <padding android:bottom="5dp" android:left="5dp" android:right="5dp" android:top="5dp" />
        </shape></item>
    <item><shape>
            <gradient android:angle="270" android:endColor="@color/info_normal" android:startColor="@color/info_normal" />

            <stroke android:width="3dp" android:color="@color/info_normal" />

            <corners android:radius="3dp" />

            <padding android:bottom="5dp" android:left="5dp" android:right="5dp" android:top="5dp" />
        </shape></item>

</selector>



One more thing is useful for shape called shape type"
there are four types of shape available in android.
 
rectangle A rectangle that fills the containing View. This is the default shape.
oval An oval shape that fits the dimensions of the containing View.
line A horizontal line that spans the width of the containing View. This shape requires the <stroke> element to define the width of the line.
ring A ring shape.
  
 
Our new android application for EGreeting.Have a look to it.
 The Greetings Android Application 

Download:-

 



NovaRadix Android Application Development Team
NovaRadix Technology
WWW.NOVARADIX.COM


 

Call web services easily

get source code from here, Download