现在的位置: 首页 > 综合 > 正文

ImageSwitcher 使用方法

2017年12月25日 ⁄ 综合 ⁄ 共 1129字 ⁄ 字号 评论关闭

java代码:

final ImageSwitcher switcher = (ImageSwitcher)findViewById(R.id.switcher);
this.image.setInAnimation(AnimationUtils.makeInAnimation(this, true)); // true从左淡入,false从右淡入
this.image.setOutAnimation(AnimationUtils.makeOutAnimation(this, true)); // true从右淡出,false从左淡入出
//this.image.setInAnimation(this, android.R.anim.fade_in);  //淡入
//this.image.setOutAnimation(this, android.R.anim.fade_out); //淡出
switcher.setFactory(new ViewFactory()
{
    @Override
    public View makeView()
    {
        ImageView imageView = new ImageView(GridViewTest.this);
        imageView.setBackgroundColor(0xff0000);
        imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
        //LayoutParams类很重要 ,包导错了,一直报类转换异常的错误
        imageView.setLayoutParams(new ImageSwitcher.LayoutParams(
                android.widget.Gallery.LayoutParams.WRAP_CONTENT, android.widget.Gallery.LayoutParams.WRAP_CONTENT));
        return imageView;
    }
});  

XML布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageSwitcher android:id="@+id/image"
        android:layout_width="200dp"
        android:layout_height="200dp"
         />

</LinearLayout>

抱歉!评论已关闭.