一、简介

    ViewSwitcher适用于两个视图带动画效果的切换。这里实现两个视图切换的功能,并附带滑屏效果。

  二、截图

二、范例代码

    带动画效果的切换视图一和视图二。

    xml

<ViewSwitcher android:layout_alignParentBottom="true"
android:persistentDrawingCache="animation" android:id="@+id/bottom"
android:layout_width="match_parent" android:inAnimation="@android:anim/slide_in_left"
android:outAnimation="@android:anim/slide_out_right" android:layout_height="122.0dip">
<RelativeLayout android:layout_width="fill_parent"
android:layout_gravity="bottom" android:layout_marginBottom="12.0dip"
android:id="@+id/lyBottom" android:layout_height="wrap_content">
<Button android:id="@+id/btn_pre" android:text="上一步"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_toLeftOf="@+id/btn_middle"
android:layout_marginRight="150.0dip" />
<Button android:id="@+id/btn_middle" android:layout_width="wrap_content"
android:layout_centerInParent="true" android:onClick="onClick" android:visibility="invisible"
android:textSize="22.0sp"
android:layout_height="wrap_content"></Button>
<Button android:id="@+id/btn_next" android:text="下一步"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_toRightOf="@+id/btn_middle"
android:layout_marginLeft="150.0dip" />
</RelativeLayout>
<RelativeLayout android:layout_width="fill_parent"
android:layout_gravity="bottom" android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView android:src="@drawable/cube" android:id="@+id/btn_reinsure"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="150.0dip"></ImageView>
<ImageView android:src="@drawable/cyddz" android:id="@+id/btn_identity"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="@+id/btn_reinsure"
android:layout_marginLeft="124.0dip"></ImageView>
<ImageView android:src="@drawable/cykvmce" android:id="@+id/btn_insure_query"
android:layout_toRightOf="@+id/btn_identity" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginLeft="140.0dip"></ImageView>
<ImageView android:src="@drawable/m8gprs" android:id="@+id/btn_review"
android:layout_toRightOf="@+id/btn_insure_query"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="140.0dip"></ImageView>
<ImageView android:src="@drawable/th_appshareth"
android:layout_toRightOf="@+id/btn_review"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="130.0dip"></ImageView>
</RelativeLayout>
</ViewSwitcher>

代码说明:

        1. 这里使用系统自带的切换效果@android:anim/slide_in_left和@android:anim/slide_out_right。

        2. 请大家自行准备测试图片

    java
bottom = (ViewSwitcher) findViewById(R.id.bottom);
//切换为第一个
bottom.setDisplayedChild(0);
//切换到下一个
//bottom.showNext()

ViewSwitcher使用范例的更多相关文章

  1. 二、Android应用的界面编程(七)ViewAnimator及其子类[ ViewSwitcher、ImageSwitcher、TextSwitcher、ViewFlipper ]

    ViewAnimator是一个基类,它继承了FrameLayout.因此它表现出FrameLayout的特征,可以将多个View组“叠”在一起. ViewAnimator可以在View切换时表现出动画 ...

  2. C# 7.0 新功能代码范例

    随着新版本的IDE Visual Studio 15 紧锣密鼓的开发中,2016年8月24日,微软发布了与之配套的C# 7.0 preview 的新特性. 其主要特性有: 内联声明out变量 (Out ...

  3. Information Management Policy(信息管理策略)的使用范例

    基础知识 很多人都会定期收拾自己的书架或者抽屉,把里面过旧的资料拿走,为新的资料腾出空间来,这样既可以节省空间,而且当冗余资料过多的时候也会降低你查找的速度和效率.那么,在企业的SharePoint中 ...

  4. Java学习笔记13---一个循环程序的设计范例

    package welcome; import java.util.Scanner; /* * 一个循环程序的设计范例 * 首先编写仅执行一次的程序(当无循环时) * 循环的设计步骤: * 1.确定程 ...

  5. [liusy.api-SMJ]-创建工程范例 MAVEN archetype 学习阶段(一)

    由于这个架构需要好多不同能力的工程,为了创建方便减少冗余,创建工程范例尤为重要 学习阶段: 参考资料 http://maven.apache.org/archetype/maven-archetype ...

  6. 通过 UDP 发送数据的简单范例

    package j2se.core.net.udp; import java.io.IOException;import java.net.DatagramPacket;import java.net ...

  7. 分享:写了一个 java 调用 C语言 开发的动态库的范例

    分享:写了一个 java 调用 C语言 开发的动态库的范例 cfunction.h   代码#pragma once#ifdef __cplusplusextern "C" {#e ...

  8. [TypeScript] Dictionary范例

    [TypeScript] Dictionary范例 Playground http://tinyurl.com/o7czcxo Samples class Dictionary { [index: s ...

  9. [转]Backbone.js简单入门范例

    本文转自:http://dmyz.org/archives/598 11年刚开始用前端MVC框架时写过一篇文章,当时Knockout和Backbone都在用,但之后的项目全是在用Backbone,主要 ...

随机推荐

  1. oracle 空表无法导出

    1.执行该语句   select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0;  ...

  2. jQuery datepicker

    <script type="text/javascript" src="/assets/datepicker/jquery-ui-1.9.1.min.js" ...

  3. CLRS:median and order statistics

    //maximum and minimum     暴力遍历 O(n) //i-th element dicide and conquer random_selected_partition     ...

  4. SQL表自连接用法

      一个表与自身进行连接,称为自连接 问题的提出:一个网友提出这样一个SQL题目,说自己想了很久没解决,我一看,这不是很简单吗 可是自己在查询分析器调试了半天原来问题并不是那不简单 有一个学生表,里面 ...

  5. Android事件

    1.Java package com.fish.helloworld; import android.app.Activity; import android.graphics.Color; impo ...

  6. Windows Phone 显示长文本

    文采不好,将就着看,见谅 思路最重要,故本文不提供源码下载 参考项目: http://www.windowsphone.com/zh-cn/store/app/%E5%BF%83%E7%90%86fm ...

  7. MAC OS下免费下载YouTube

    YouTube上有很多不错的视频,你感兴趣的视频除了可以加入自己播放列表之外,还可以将其下载到本地收藏起来.推荐这款软件“Xilisoft Download YouTube Video for Mac ...

  8. c/c++基本问题

    1. 使用g++将文件编译成库文件 g++ -c -O2 -fPIC test.cpp -o test.o && g++ -shared -Wall -o test.so test.o ...

  9. 两张table数据同步--使用触发器

    数据同步, 如果每天同步一次的话可以使用SSIS,跑JOB等,可以同步不同的DB的数据: 实时的可以使用触发器,在同一个DB中(或者DB Link): USE [test] GO IF EXISTS( ...

  10. c语言学习的第四天2

    上图显示了float和double的精度,精度:就是指数值的精确程度,浮点类型可表示的数值范围很大,但只有几位是精确的,可以通过小 数所占的位数来获取,float小数部分最多能有7位有效数字,但绝对能 ...