download: http://www.mediafire.com/download/7j0ycdg5j2mdpvy/ViewFlipperDemos.zip
package com.ui.yogeshblogspot;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ViewFlipper;
public class Main extends Activity {
ViewFlipper flipper;
Button btBackPage;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Getting View Flipper from main.xml and assigning to flipper reference
// variable
flipper = (ViewFlipper) findViewById(R.id.viewFlipper1);
btBackPage = (Button) findViewById(R.id.btBackPage);
btBackPage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
if (flipper.isFlipping())// Checking flipper is flipping or not.
{
flipper.stopFlipping(); // stops the flipping .
}
flipper.showPrevious();// shows the next view element of ViewFlipper
}
});
}
public void flipByClick(View v) {
if (flipper.isFlipping())// Checking flipper is flipping or not.
{
flipper.stopFlipping(); // stops the flipping .
}
flipper.showNext();// shows the next view element of ViewFlipper
}
public void flipByInterval(View v) {
flipper.setFlipInterval(500);// setting the interval 500 milliseconds
flipper.startFlipping(); // views flipping starts.
}
}
--------------------------------
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" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<!-- Calling flipByInterval() method of Activity class -->
<Button
android:id="@+id/btBackPage"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_weight="0.40"
android:text="Back Flip"
android:background="@android:color/holo_green_dark"/>
<Button
android:id="@+id/flipbyclick"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_weight="0.40"
android:background="@android:color/holo_green_dark"
android:onClick="flipByClick"
android:layout_marginLeft="10dp"
android:text="Flip By Click" />
<!-- calling flipByClick() method of Activity class -->
</LinearLayout>
<!-- ViewFlipper can contains any view elements in this case it contains 5 ImageView view Component with different Images -->
<ViewFlipper
android:id="@+id/viewFlipper1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/dialog_text" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img1" />
<!-- Setting img1 from drawable folder in ImageView -->
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img2" />
<!-- Setting img2 from drawable folder in ImageView -->
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img3" />
<!-- Setting img3 from drawable folder in ImageView -->
<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img4" />
<!-- Setting img4 from drawable folder in ImageView -->
<ImageView
android:id="@+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img5" />
<!-- Setting img5 from drawable folder in ImageView -->
<ImageView
android:id="@+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img6" />
<!-- Setting img6 from drawable folder in ImageView -->
</ViewFlipper>
<Button
android:id="@+id/flipbyinterval"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:onClick="flipByInterval"
android:text="Flip By Interval" />
</LinearLayout>
--------------------------------
dialog_text.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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".50" >
<Button
android:id="@+id/imageViewSearchBanner"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:text="new btn" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".50" >
<Button
android:id="@+id/ivForText"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:text="other btn" />
</LinearLayout>
</LinearLayout>
package com.ui.yogeshblogspot;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ViewFlipper;
public class Main extends Activity {
ViewFlipper flipper;
Button btBackPage;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Getting View Flipper from main.xml and assigning to flipper reference
// variable
flipper = (ViewFlipper) findViewById(R.id.viewFlipper1);
btBackPage = (Button) findViewById(R.id.btBackPage);
btBackPage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
if (flipper.isFlipping())// Checking flipper is flipping or not.
{
flipper.stopFlipping(); // stops the flipping .
}
flipper.showPrevious();// shows the next view element of ViewFlipper
}
});
}
public void flipByClick(View v) {
if (flipper.isFlipping())// Checking flipper is flipping or not.
{
flipper.stopFlipping(); // stops the flipping .
}
flipper.showNext();// shows the next view element of ViewFlipper
}
public void flipByInterval(View v) {
flipper.setFlipInterval(500);// setting the interval 500 milliseconds
flipper.startFlipping(); // views flipping starts.
}
}
--------------------------------
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" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<!-- Calling flipByInterval() method of Activity class -->
<Button
android:id="@+id/btBackPage"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_weight="0.40"
android:text="Back Flip"
android:background="@android:color/holo_green_dark"/>
<Button
android:id="@+id/flipbyclick"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_weight="0.40"
android:background="@android:color/holo_green_dark"
android:onClick="flipByClick"
android:layout_marginLeft="10dp"
android:text="Flip By Click" />
<!-- calling flipByClick() method of Activity class -->
</LinearLayout>
<!-- ViewFlipper can contains any view elements in this case it contains 5 ImageView view Component with different Images -->
<ViewFlipper
android:id="@+id/viewFlipper1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/dialog_text" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img1" />
<!-- Setting img1 from drawable folder in ImageView -->
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img2" />
<!-- Setting img2 from drawable folder in ImageView -->
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img3" />
<!-- Setting img3 from drawable folder in ImageView -->
<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img4" />
<!-- Setting img4 from drawable folder in ImageView -->
<ImageView
android:id="@+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img5" />
<!-- Setting img5 from drawable folder in ImageView -->
<ImageView
android:id="@+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img6" />
<!-- Setting img6 from drawable folder in ImageView -->
</ViewFlipper>
<Button
android:id="@+id/flipbyinterval"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:onClick="flipByInterval"
android:text="Flip By Interval" />
</LinearLayout>
--------------------------------
dialog_text.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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".50" >
<Button
android:id="@+id/imageViewSearchBanner"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:text="new btn" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".50" >
<Button
android:id="@+id/ivForText"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:text="other btn" />
</LinearLayout>
</LinearLayout>
No comments:
Post a Comment