ImageSwitvher的用法
ImageSwitcher的继承关系是:
ImageSwitcher继承自ViewSwitcher,用于View之间的切换
ViewSwither继承自ViewAnimator,顾名思义可知,这个控件可以实现View之间切换时候的动画效果。
ImageSwitcher的主要方法有:
is.setFactory(new ViewFactory(){
@Override
public View makeView() {
ImageView i = new ImageView(Main.this);
i.setBackgroundColor(0xFF000000);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new ImageSwitcher.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
return i;
}});
ViewFactory是ViewSwitcher的内部接口,做图片之间的切换时,要在makeView()方法中返回ImageView对象。 ImageSwitcher自身的方法除了构造方法之外,只有三个:
setImageResource(int resid);
setImageURI(Uri uri);
setImageDrawable(Drawable drawable);
这三个方法很好理解,在需要切换的事件中调用即可。 如果要实现动画效果只需调用:
setInAnimation(Animation inAnimation);
setOutAnimation(Animation inAnimation);

浙公网安备 33010602011771号