ImageView setlayoutparams 出错

ImageView setlayoutparams 出错


ImageView 不可以用viewgroup的layoutparams


要用 ImageSwitcher的 layoutparams

 

 

 

转代码:

 

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

 

你可能感兴趣的:(LayoutParams)