[Android]ViewSwitcher使用范例
作者:农民伯伯 | 出处:博客园 | 2011/9/3 10:32:06 | 阅读31次
前言
虽然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>
代码说明:
1. 这里使用系统自带的切换效果@android:anim/slide_in_left和@android:anim/slide_out_right。
2. 请大家自行准备测试图片
java
bottom = (ViewSwitcher) findViewById(R.id.bottom);
//切换为第一个
bottom.setDisplayedChild(0);
//切换到下一个
//bottom.showNext()
- 大小: 10.5 KB
- 大小: 2.1 KB
分享到:
相关推荐
ViewFlipper和ViewSwitcher的使用:屏幕切换指的是在同一个Activity内屏幕见的切换,最长见的情况就是在一个FrameLayout内有多个页面,比如一个系统设置页面;一个个性化设置页面。 通过查看OPhone API文档可以...
主要介绍了Android开发之ViewSwitcher用法,结合实例形式分析了ViewSwitcher的功能、使用方法与相关注意事项,需要的朋友可以参考下
主要技术点:ViewSwitcher(它只能添加两个子view,有兴趣的可以修改源码,继承使用,使它支持更多的视图,但不建议这么做),另外就是handler调用runnable了。有兴趣的下载下吧,本例只收你1分!
使用ViewSwitcher实现文字图片上下滚动
ViewSwitcher和ImageSwitcher的Demo,只是简单的使用,参考了http://www.cnblogs.com/over140/archive/2011/09/03/2121526.html
2.作为ViewSwitcher的子类,它比ViewSwitcher使用更加方便,主要体现在:①. 重写了setNext() ②. 重写了showPrevious()方法。所以其实用起来,要比ViewSwitcher更为方便。 3.中重要的是:ImageSwitcher增加了图片...
NULL 博文链接:https://zhanhao.iteye.com/blog/1175106
在使用ImageSwitcher切换图片时,定义的Activity类必须实现ViewSwitcher.ViewFactory接口(视图切换工厂),并通过makeView()方法来创建用于显示图片的ImageView。在使用ImageSwitcher切换图片时,可以通过Animation...
5.其它细节一些的比如listview的显示控制、Bitmap的OutOfMemoryError的控制,viewswitcher的使用,布局的控制,sharedpreference的使用,handler的使用等等 由于是学习用的,开发出的东西兼容性可能不太好(没测过...
在使用ImageSwitcher时,必须实现ViewSwitcher.ViewFactory接口,并通过makeView()方法创建用于显示图片的ImageView对象。makeView()方法将返回一个显示图片的ImageView。在使用ImageSwitcher组件时,还有一个非常...
当ViewStub使用在布局文件中时,当程序inflate布局文件时,ViewStub本身也会被解析,且占据内存控件,但是与其他控件相比,主要区别体现在以下几点: 1.当布局文件inflate时,ViewStub控件虽然也占据内存,但是相...
一些常见的切换效果 这是一个小演示展示文字自动横向滚动,竖向滚动和查看竖向滚动。 自定义+动画控制 1,文字横向滚动只是直接用TextView实现...5,ViewSwitcher + Handler实现切换 ViewFlipper实现 以下是使用ViewFli
在使用ImageSwitcher时,必须实现ViewSwitcher.ViewFactory接口,并通过makeView()方法来创建用于显示图片的ImageView。makeView()方法将返回一个显示图片的ImageView。在使用图像切换器时,还有一个方法非常重要,...
Android平台下ImageSwitcher的使用,可以参见博客:http://www.cnblogs.com/plokmju/p/android_ImageSwitcher.html
主要为大家详细介绍了Android TextSwitcher文本切换器和ViewFlipper的使用方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这个实现起来并不难,可以用一个ViewSwitcher,Checkbox和删除按扭是放入其中,让ViewSwitcher来控制显示哪一个,正常情况下显示Checkbox,隐藏删除按扭,然后当点击Item时就显示删除按扭,隐藏Checkbox,这
图像切换器(ImageSwitcher),用于实现类似于windows操作系统下的windows照片查看器中的上一张 下一张切换图片的功能,在使用ImageSwitcher时,必须实现ViewSwitcher.ViewFactory接口,并通过makeView()方法来创建...