标签:android
ViewFlipper继承于ViewAnimator,它和AdapterViewFlipper有着许多的相似的地方。
package peng.liu.test;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewFlipper;
import android.widget.ViewSwitcher;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MainActivity extends Activity {
private ViewFlipper viewFlipper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
viewFlipper = (ViewFlipper) findViewById(R.id.details);
}
public void next(View view){
viewFlipper.setInAnimation(this,R.anim.slide_in);
viewFlipper.setOutAnimation(this,R.anim.slide_out);
viewFlipper.showNext();
viewFlipper.stopFlipping();
}
public void prev(View view){
viewFlipper.setInAnimation(this,R.anim.slide_in);
viewFlipper.setOutAnimation(this,R.anim.slide_out);
viewFlipper.showPrevious();
viewFlipper.stopFlipping();
}
public void auto(View view){
viewFlipper.setInAnimation(this,R.anim.slide_in);
viewFlipper.setOutAnimation(this,R.anim.slide_out);
viewFlipper.startFlipping();
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
>
<ViewFlipper
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/details"
android:flipInterval="1000"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"/>
</ViewFlipper>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="<"
android:onClick="next"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=">"
android:onClick="prev"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="自动播放"
android:onClick="auto"
android:layout_centerInParent="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
Android的ViewFlipper-android学习之旅(三十五)
标签:android
原文地址:http://blog.csdn.net/lpjishu/article/details/46358739