Android ViewFliper
屏幕切换指的是在同一个Activity内屏幕见的切换,最长见的情况就是在一个FrameLayout内有多个页面,比如一个系统设置页面;一个个性化设置页面。
通过查看 OPhone API文档可以发现,有个android.widget.ViewAnimator类继承至FrameLayout,ViewAnimator类的作用是为FrameLayout里面的View切换提供动画效果。该类有如下几个和动画相关的函数:
- setOutAnimation: 设置View退出屏幕时候使用的动画,参数setInAnimation函数一样。
- showNext: 调用该函数来显示FrameLayout里面的下一个View。
- showPrevious: 调用该函数来显示FrameLayout里面的上一个View。
- isFlipping: 用来判断View切换是否正在进行
- setFilpInterval:设置View之间切换的时间间隔
- startFlipping:使用上面设置的时间间隔来开始切换所有的View,切换会循环进行
- stopFlipping: 停止View切换
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <ViewFlipper android:id="@+id/details"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:persistentDrawingCache="animation"
- android:flipInterval="1000"
- android:inAnimation="@anim/push_left_in"
- android:outAnimation="@anim/push_left_out"
- >
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <Button
- android:text="Next"
- android:id="@+id/Button_next1"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </Button>
- <ImageView
- android:id="@+id/image1"
- android:src="@drawable/dell1"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </ImageView>
- </LinearLayout>
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <Button
- android:text="Next"
- android:id="@+id/Button_next2"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </Button>
- <ImageView
- android:id="@+id/image2"
- android:src="@drawable/lg"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </ImageView>
- </LinearLayout>
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <Button
- android:text="Next"
- android:id="@+id/Button_next3"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </Button>
- <ImageView
- android:id="@+id/image3"
- android:src="@drawable/lenovo"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </ImageView>
- </LinearLayout>
- </ViewFlipper>
- </LinearLayout>
- res\anim\push_left_in.xml
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android">
- <translate
- android:fromXDelta="100%p"
- android:toXDelta="0"
- android:duration="500"/>
- <alpha
- android:fromAlpha="0.0"
- android:toAlpha="1.0"
- android:duration="500" />
- </set>
- res\anim\push_left_out.xml
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android">
- <translate
- android:fromXDelta="0"
- android:toXDelta="-100%p"
- android:duration="500"/>
- <alpha
- android:fromAlpha="1.0"
- android:toAlpha="0.0"
- android:duration="500" />
- </set>
- public class TestActivity extends Activity {
- private ViewFlipper mViewFlipper;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button buttonNext1 = (Button) findViewById(R.id.Button_next1);
- mViewFlipper = (ViewFlipper) findViewById(R.id.flipper);
- buttonNext1.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- //在layout中定义的属性,也可以在代码中指定
- // mViewFlipper.setInAnimation(getApplicationContext(), R.anim.push_left_in);
- // mViewFlipper.setOutAnimation(getApplicationContext(), R.anim.push_left_out);
- // mViewFlipper.setPersistentDrawingCache(ViewGroup.PERSISTENT_ALL_CACHES);
- // mViewFlipper.setFlipInterval(1000);
- mViewFlipper.showNext();
- //调用下面的函数将会循环显示mViewFlipper内的所有View。
- // mViewFlipper.startFlipping();
- }
- });
- Button buttonNext2 = (Button) findViewById(R.id.Button_next2);
- buttonNext2.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- mViewFlipper.showNext();
- }
- });
- Button buttonNext3 = (Button) findViewById(R.id.Button_next3);
- buttonNext3.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- mViewFlipper.showNext();
- }
- });
- }
- }
- class TestActivity extends Activity implements OnGestureListener , OnDoubleTapListener
- public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
- float velocityY) {
- Log.d(tag, "...onFling...");
- if(e1.getX() > e2.getX()) {//move to left
- mViewFlipper.showNext();
- }else if(e1.getX() < e2.getX()) {
- mViewFlipper.setInAnimation(getApplicationContext(), R.anim.push_right_in);
- mViewFlipper.setOutAnimation(getApplicationContext(), R.anim.push_right_out);
- mViewFlipper.showPrevious();
- mViewFlipper.setInAnimation(getApplicationContext(), R.anim.push_left_in);
- mViewFlipper.setOutAnimation(getApplicationContext(), R.anim.push_left_out);
- }else {
- return false;
- }
- return true;
- }
- public boolean onDoubleTap(MotionEvent e) {
- Log.d(tag, "...onDoubleTap...");
- if(mViewFlipper.isFlipping()) {
- mViewFlipper.stopFlipping();
- }else {
- mViewFlipper.startFlipping();
- }
- return true;
- }
- public GestureDetector(OnGestureListener listener) {
- this(null, listener, null);
- }
- public GestureDetector(Context context, OnGestureListener listener, Handler handler) {
- if (handler != null) {
- mHandler = new GestureHandler(handler);
- } else {
- mHandler = new GestureHandler();
- }
- mListener = listener;
- if (listener instanceof OnDoubleTapListener) {
- setOnDoubleTapListener((OnDoubleTapListener) listener);
- }
- init(context);
Android ViewFliper相关推荐
- Android类似于滚动的通知栏实现
控件类似于网页上的滚动播报栏 图片1: 图片2: 如上图,实现滚动栏里多条消息的自切换: 点击后获取具体内容. 简单是实现代码: public class PublicNoticeView exten ...
- Android中的动画
视频课:https://edu.csdn.net/course/play/7621 学习内容 Ø 帧动画 Ø 补间动画 Ø 动画方式切换组件 能力目标 Ø 掌握Android中动画的基本概念及分类 Ø ...
- android文件管理器--界面效果二(layout)
主界面xml文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...
- 一步一步实现一款实用的Android广告栏
源码: BannerLayoutDemo 有图有真相: bannerLayoutDemo 开源界有一句很有名的话叫"不要重复发明轮子",当然,我今天的观点不是要反驳这句话,轮 ...
- Android一步一步实现一款实用的Android广告栏
源码:BannerLayoutDemo 有图有真相: bannerLayoutDemo 开源界有一句很有名的话叫"不要重复发明轮子",当然,我今天的观点不是要反驳这句话,轮子理论给 ...
- Android开发之ViewFlipper
Android开发之ViewFlipper /* * Android开发之ViewFlipper * 北京Android俱乐部群:167839253 * Created on: 2012-7-25 ...
- android tab布局框架,android Tab页详解
一.android Tab的实现方式总结 说起Tab页,基本每个做移动端的都会需要.iOS中内置了一个,所以ioser用起来很方便.而android这一块就比较乱. 木器实现Tab效果的方式,主要有4 ...
- android Tab页详解
一.android Tab的实现方式总结 说起Tab页,基本每个做移动端的都会需要.iOS中内置了一个,所以ioser用起来很方便.而android这一块就比较乱. 木器实现Tab效果的方式,主要有4 ...
- Unity5.6+ 导出Android 应用程序apk的环境配置及导出过程
首先下载并安装安卓SDK和java的JDK 安卓sdk下载: http://www.android-studio.org/ 也可以在这下载: 链接:http://pan.baidu.com/s/1bp ...
最新文章
- Intellij 如何在新窗口中打开项目
- ubuntu运行Faster R-CNN
- vb6 串口同时读取写入数据怎么避免冲突_实例:S7-200 SMART通过Modbus-RTU读取温湿度传感器数据...
- ad20如何画出pcb板大小_NAKANISHI分板机主轴在PCB分板上切削案例
- u8 和 char如何转化_如何编写高效率稳定的单片机代码
- 数据结构(四)---栈的顺序存储的实现---java版
- 对几个submission文件迅速做voting操作
- 【车间调度】基于matlab多层编码遗传算法求解车间调度问题【含Matlab源码 035期】
- 字符串替换(NYOJ)
- 【一、视频处理】FPGA驱动OV7725摄像头模块
- ai跟随路径_怎么在ai中创建文本路径?Ai中怎样沿路径创建文本?
- linux美元符号切换为井号,struts2 (# % $)井号,百分号,美元符号的含义和使用方法举例...
- php 安全禁止函数,禁用危险函数-PHP安全
- 加减乘除等符号大全中英对照,在英语中的用法
- 解决在Filter中读取Request中的流后,后续controller或restful接口中无法获取流的问题
- android wifi取消自动连接网络,Android 11新增无线网络连接安全策略 可以不自动连接某些特定WiFi...
- 两轮自平衡机器人(一)---Simscape物理建模
- 自动计算所有子对象包包围盒
- 23-【kubernetes】二进制方式安装k8s集群遇到的问题
- Qt平台添加OpenCV库