Showing posts with label View. Show all posts
Showing posts with label View. Show all posts

Tuesday, 7 May 2013

View Flipper in android example


Simple ViewAnimator that will animate between two or more views that have been added to it. Only one child is shown at a time. If requested, can automatically flip between each child at a regular interval.
The ViewFlipper is a nifty widget that can be used to slide views in and out of the user’s current view port. At times I find it a handy UI replacement for the tab widget (which I’ve stated before I’m not overly fond of). What I like most about the ViewFlipper is the slick user experience. It’s the same sort of effect that is prevalent on Windows Phone 7, and was used by Google to jazz up the latest incarnation of the Android Market.
Despite the widget only recently gaining popularity on Android, it’s been around since version 1.0 of the API. (Read the official ViewFlipper documentation.) However, I don’t think the developer documentation makes it immediately obvious how to use the widget in your applications. In particular, puzzling through the sliding in and out animation transitions can be a little tough. Maybe not as tough as ignoring the candy bowl sitting on my kitchen counter, assuring me no one will notice if I take just one more Laffy Taffy, but still, it requires you to put on your thinking cap. If you’d like to download and import the entire project detailed in this tutorial, you can do so here.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="View Flipper Demo" />

<ViewFlipper
android:id="@+id/view_flipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="6dip" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A dog limps into a saloon and says..."
android:textColor="#00ff00"
android:textSize="14sp"
android:textStyle="bold" >
</TextView>
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I&apos;m looking for the man who shot my paw!"
android:textColor="#00ff00"
android:textSize="14sp"
android:textStyle="bold" >
</TextView>
</LinearLayout>
</ViewFlipper>

</LinearLayout>

MainActivity.java

package com.example.viewflipper;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.ViewFlipper;

public class MainActivity extends Activity {

private ViewFlipper vf;
private float lastX;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vf = (ViewFlipper) findViewById(R.id.view_flipper);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

public boolean onTouchEvent(MotionEvent touchevent) {
switch (touchevent.getAction()) {
case MotionEvent.ACTION_DOWN: {
lastX = touchevent.getX();
break;
}
case MotionEvent.ACTION_UP: {
float currentX = touchevent.getX();
if (lastX < currentX) {
if (vf.getDisplayedChild() == 0)
break;
vf.setInAnimation(this, R.anim.in_from_left);
vf.setOutAnimation(this, R.anim.out_to_right);
vf.showNext();
}
if (lastX > currentX) {
if (vf.getDisplayedChild() == 1)
break;
vf.setInAnimation(this, R.anim.in_from_right);
vf.setOutAnimation(this, R.anim.out_to_left);
vf.showPrevious();
}
break;
}
}
return false;
}

}

and Two another animation file;

to create that file first you need to create a new folder into /res named animation and into that you need to create xml files.

in_from_left.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<!--
<translate
android:duration="1400"
android:fromXDelta="-100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" /> -->
<!-- <scale android:duration="100"
android:fromXScale="100%"
android:fromYScale="0%"
android:repeatMode="reverse"/>
-->
<rotate android:fromDegrees="5"
android:toDegrees="50"
android:duration="5000"/>

</set>
in_from_right.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >

<translate
android:duration="1400"
android:fromXDelta="100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />

</set>

Screen shot


Thanks 

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

Call web services easily

get source code from here, Download