Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用适配器设置栅格视图中最后添加的子对象的动画_Java_Android - Fatal编程技术网

Java 使用适配器设置栅格视图中最后添加的子对象的动画

Java 使用适配器设置栅格视图中最后添加的子对象的动画,java,android,Java,Android,我有一个GridView,我一直在向其中添加视图。当视图添加到网格中时,我希望它能够制作动画。但是,由于我必须使用setAdapter()刷新GridView,因此它会在重新添加所有视图时设置所有视图的动画。这有什么关系吗 下面是我要添加的视图代码: public class GridImageView extends ImageView { public GridImageView(Context context) { super(context); } public GridI

我有一个
GridView
,我一直在向其中添加视图。当视图添加到网格中时,我希望它能够制作动画。但是,由于我必须使用
setAdapter()
刷新
GridView
,因此它会在重新添加所有视图时设置所有视图的动画。这有什么关系吗

下面是我要添加的视图代码:

public class GridImageView extends ImageView {


public GridImageView(Context context) {
    super(context);
}

public GridImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public GridImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    ScaleAnimation anim = new ScaleAnimation(0,1,0,1);
    anim.setDuration(1000);
    anim.setFillAfter(true);
    this.startAnimation(anim);
 }
}

一如既往,感谢您的帮助

感谢Luksprog的建议,我在自定义视图中设置了一个标志,该标志将确定视图添加到栅格视图时是否应设置动画

public class GridImageView extends ImageView
{

   private boolean _animate = false;
   public GridImageView(Context context) {
       super(context);
   }

   public GridImageView(Context context, AttributeSet attrs) {
       super(context, attrs);
   }

   public GridImageView(Context context, AttributeSet attrs, int defStyle) {
       super(context, attrs, defStyle);
   }

   @Override
   protected void onAttachedToWindow() {

       if(_animate){

            super.onAttachedToWindow();
            ScaleAnimation anim = new ScaleAnimation(0,1,0,1);
            anim.setDuration(1000);
            anim.setFillAfter(true);
            this.startAnimation(anim);
       }
   }


   public void set_animate(boolean _animate) {
       this._animate = _animate;
   }
}

我的适配器在其
GetView()
函数中检查它是否是数组列表中的最后一个,如果是,则将标志设置为true

    if( i == ( _gridDetailsArrayList.size() - 1 ))
        holder.gridImage.set_animate(true);

在适配器的
getView()
方法中,您可以看到您是否处于最后一个位置,并以某种方式向
ImageView
发出信号,表示它应该自行设置动画。谢谢,这似乎很好地工作。将发布我的解决方案,