7.8. ImageSwitcher(图片切换组件)
ImageSwitcher组件的主要功能是完成图片的切换显示,例如用户在进行图片浏览的时候,可以通过按钮点击一张张的切换显示的图片,而且使用ImageSwitcher组件在每次切换的时候也可以为其增加一些动画的效果,类的继承结构如下:
|
如果要想真正的实现图片的切换操作,那么问题的关键就在于ViewFactory工厂的使用上,它是ViewSwitcher的一个内部接口。
public static interface ViewSwitcher.ViewFactory |
在这个接口中有一个操作方法:
public abstract View makeView () |
这个方法的作用是创建一个View显示的组件。
配置:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/MyLayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageSwitcher android:id="@+id/myImageSwitcher" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/butPrevious" android:text="上一张图片" android:enabled="false" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <Button android:id="@+id/butNext" android:text="下一张图片" android:enabled="true" android:layout_width="wrap_content" &nbs |