ImageView setlayoutparams 出错

ImageView 不可以用viewgrouplayoutparams

要用 ImageSwitche layoutparams

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;
    }
});  


展开阅读全文

没有更多推荐了,返回首页