ViewSwitcher的使用方法
来源:互联网 发布:鑫居安消防手电筒 淘宝 编辑:程序博客网 时间:2024/05/17 08:04
前言
虽然ViewSwitcher的中文API早已翻译出来,但一直没有在项目中使用过,也没有搜到很合适很简单的中文例子,这里与大家一起探讨和分享一下其用法。
声明
欢迎转载,但请保留文章原始出处:)
博客园:http://www.cnblogs.com
农民伯伯: http://over140.cnblogs.com
相关API
Android 中文API (61) —— ViewSwitcher
正文
一、简介
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>
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()
//切换为第一个
bottom.setDisplayedChild(0);
//切换到下一个
//bottom.showNext()
- ViewSwitcher的使用方法
- ViewSwitcher的简单使用
- ViewSwitcher的简单使用
- ViewSwitcher
- ViewSwitcher
- 一个ViewSwitcher引发的血案!
- android中ViewSwitcher的使用
- android ViewSwitcher的用法介绍
- Android中viewSwitcher的使用
- 动画特效的应用----ViewSwitcher控件
- Android ViewSwitcher 的功能与用法
- Android ViewSwitcher 的功能与用法
- Android ViewSwitcher 的功能与用法
- Android ViewSwitcher 的功能与用法
- ViewSwitcher的功能与用法View
- android ViewSwitcher实现视图的轻松切换
- ViewSwitcher和TextSwithcher打造不一样的视觉效果
- <ViewSwitcher>的简单功能与用法
- Apache-ftpserver在eclipse下的部署和使用
- sizeof 关键字
- 【js与jquery】订单提交页发送短信功能
- abstract interface和interface的区别
- 3、const的用法---普通用法+用于指针
- ViewSwitcher的使用方法
- CKeditor 配置使用
- 4、JAVA中字符串的拷贝、arraycopy()的用法
- centos中查看版本信息
- Xtreme.Toolkit.Pro.v9.60 +VC6.0安装使用
- IMU
- sqlite3 支持的数据类型 常用函数
- JavaScript中匿名函数的用法及优缺点
- MongoDB学习笔记(三) 在MVC模式下通过Jqgrid表格操作MongoDB数据