ImageSwitcher is = (ImageSwitcher) findViewById(R.id. is );
//设置图片动画
is.setInAnimation(AnimationUtils. loadAnimation( this, R.anim.in ));
is.setOutAnimation(AnimationUtils. loadAnimation( this, R.anim.out ));
is.setFactory( new ViewFactory() {
@Override
public View makeView() {
ImageView iv = new ImageView(MainActivity.this );
iv.setBackgroundColor(Color. RED);
iv.setScaleType(ScaleType. FIT_CENTER);
iv.setLayoutParams( new ImageSwitcher.LayoutParams(
ImageSwitcher.LayoutParams. WRAP_CONTENT,
ImageSwitcher.LayoutParams. WRAP_CONTENT));
return iv;
}
});
通过 is.setImageResource(图片资源id);设置显示的图片