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

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. 新浪API登录实例

    步骤一:添加网站 进入新浪微博开放平台,http://open.weibo.com/apps 进入“管理中心“,点击”创建应用”,选择“网页应用”,填写相应的信息后提交. 步骤二:Oauth2.0授权 ...

  2. WPF MVVM笔记

    学习了一番WPF MVVM,记录一下,微软的连接(https://msdn.microsoft.com/zh-cn/magazine/dd419663.aspx) 1.mvvm就是model,view ...

  3. 硬盘可以支持140万小时(也就是159年)的MTBF(硬盘只是一次性的投入)

    1.硬盘的的确确是一个一次性投入: 最普通的家用硬盘寿命都可以到达平均5年以上:企业级的硬盘的寿命更是长的离谱,如这个西数为数据中心提供的硬盘: WD Re:页面上说明该种硬盘可以支持140万小时(也 ...

  4. 为什么360、百度、腾讯出的Mac端云盘客户端都只有同步盘?(用户量小,同步盘开发成本低,Linux下都没有客户端)

    如题,顾名思义,同步盘是用来同步的,不具备增量的功能,像这三家在Windows端出的客户端都是即有同步也有增量的. 陆续出来的,可能大家更多的是跟随策略,不得不提dropbox是这样的形式.mac电脑 ...

  5. 浅谈网络I/O多路复用模型 select & poll & epoll

    http://blog.csdn.net/nk_test/article/details/50662946

  6. c# 向驱动打印机发送命令打开钱箱

    引用的dll 链接: https://pan.baidu.com/s/1MjwmfvBCPTBq1QNapKzDmg 提取码: 9wuf [DllImport("Drawcash.dll&q ...

  7. 深入浅出RPC——深入篇(转载)

    本文转载自这里是原文 <深入篇>我们主要围绕 RPC 的功能目标和实现考量去展开,一个基本的 RPC 框架应该提供什么功能,满足什么要求以及如何去实现它? RPC 功能目标 RPC的主要功 ...

  8. 层次关系表格,不用递归,快速检索。HierarchyId

    最近这几天写了个T4自动实现EF code first和Ado的存储过程.使用过程中发现了一个Sql的类型为HierarchyId.看到时真是百思不得齐姐.算了查一下MSDN吧.从微软官网找到了Hie ...

  9. 打开并锁定一个文件(使用LockFile API函数)

    var aHandle : THandle; aFileSize : Integer; aFileName : String; procedure TForm1.Button3Click(Sender ...

  10. 【Linux】Linux下设备网卡以及硬件管理等

    这是Linux下网络硬件管理的基础知识,虽然平时用到的可能比软件的少一点,但是作为基础命令,还是需要记住,以免用时又得查询. 本文参考官方文档:https://wiki.ubuntu.com.cn/% ...