需要注意的地方已在代码中表明

package cn.com.sxp;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ViewFlipper; public class ViewFlipperActivity extends Activity {
// 该例子显示,一个viewFlipper加载了三个线性布局,每个线性布局包含一个button,一个imageView。
// 这三个线性布局不是同时显示,是轮番显示,一个线性布局按照动画效果向左离去,另一个线性布局从右而来
private ViewFlipper viewFlipper = null;
Button btnOne = null, btnTwo = null, btnThree = null; /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); btnOne = (Button) findViewById(R.id.btnOne);
viewFlipper = (ViewFlipper) findViewById(R.id.vf);
btnOne.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// 在layout中定义的属性,也可以在代码中指定
// setInAnimation():
// Specifies the animation 动画 used to animate a View that enters the screen.
// Parameters
// context The application's environment.
// resourceID The resource id of the animation.
//
// Return the context of the single, global Application object of the current process. This
// generally should only be used if you need a Context whose lifecycle is separate from the
// current context, that is tied to the lifetime of the process rather than the current
// component.
// viewFlipper.setInAnimation(getApplicationContext(), R.anim.push_left_in); // setOutAnimation():
// Specifies the animation used to animate a View that exit the screen.
// viewFlipper.setOutAnimation(getApplicationContext(), R.anim.push_left_out); // setPersistentDrawingCache():
// Indicates what types of drawing caches should be kept in memory after they have been
// created.
// viewFlipper.setPersistentDrawingCache(ViewGroup.PERSISTENT_ALL_CACHES); // setFlipInterval();
// How long to wait before flipping to the next view
// viewFlipper.setFlipInterval(1000);
// showNext()
// Manually shows the next child.
// viewFlipper.showNext();
// 调用下面的函数将会循环显示mViewFlipper内的所有View。
// mViewFlipper.startFlipping();
}
}); btnTwo = (Button) findViewById(R.id.btnTwo);
btnTwo.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
viewFlipper.showNext();
} }); btnThree = (Button) findViewById(R.id.btnThree);
btnThree.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
viewFlipper.showNext();
} }); }
}

  运行效果如下;

点击按钮,即可看到左右换的图片。

android_viewFlipper(一)的更多相关文章

  1. Android_ViewFlipper

    xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...

  2. android 基本控件使用

    http://tech.it168.com/a2012/0321/1327/000001327704.shtml Android_ListView_用代码控制ListView的位置 有三种方法 mli ...

随机推荐

  1. Simple BeamSearch Codes for Python

    Code from: https://github.com/SeitaroShinagawa/simple_beamsearch probs = [[[],[0.3,0.7]], [[0],[0.1, ...

  2. kettle设计器连接oracle RAC时的连接字符串

    1.不需要填写主机名2.数据库名写如下连接字符串:(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = IP地址)(PORT = 1521))(CONNEC ...

  3. UWP入门(七)--SplitView详解与页面跳转

    原文:UWP入门(七)--SplitView详解与页面跳转 官方文档,逼着自己用英文看,UWP开发离不开官方文档 1. SplitView 拆分视图控件 拆分视图控件具有一个可展开/可折叠的窗格和一个 ...

  4. UWP ListView嵌套ListView

    要求:加载全部的订单,每个订单里面有一个或者多个产品,在列表中要展现出来, 1. xaml界面 步骤:1.这里使用的是x:bind绑定所以要引入实体类命名空间(OrderList集合中类的命名空间): ...

  5. 解决com.android.dex.DexException: Multiple dex files define Lcom/google/gson/JsonSerializer;

    我在开发Windows Azure的Mobile Service(隔天补上创建过程)的安卓客户端时,报出了com.android.dex.DexException: Multiple dex file ...

  6. 使用SqlSugar封装的数据层基类

    首先简单封装了个DbContext public class DbContext { #region 属性字段 private static string _connectionString; /// ...

  7. VM中linux和windows主机进行串口通信

    最近在做关于AIS的内容.为了对AIS电文进行解码,串口收发. 数据有PC机模拟发送,为了调试方便,不用次次将程序放到开发板上运行,所以利用pc主机和虚拟机进行串口通信模拟该过程. 首先需要用到一个软 ...

  8. QTableView中加入Check列实现,无需Delegate(使用::data(),Qt原生支持)

    通过Delegate创建QCheckBox来实现的Check列,只有在该列进入编辑模式时才能够Check/Uncheck.这显然不是我们想要的,网上翻来翻去,在一个国外论坛中看到了无需Delegate ...

  9. is和==的区别以及编码和解码

    一.is和==的区别 python中对象包含的三个基本要素分别是:id(身份标识),type(数据类型),value(值) is和==都是对对象进行比较判断的,但对对象比较判断的内容不同. ★==是p ...

  10. java.lang.ClassNotFoundException: org.jaxen.JaxenException 解决方法

    当遇到如下exception时, May 11, 2017 4:23:17 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE ...