Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.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
Android 使用InterpolateTime==1调用了两次applyTransformation_Android_Animation - Fatal编程技术网

Android 使用InterpolateTime==1调用了两次applyTransformation

Android 使用InterpolateTime==1调用了两次applyTransformation,android,animation,Android,Animation,我有一个列表视图,其项目需要用动画折叠,然后删除。我使用动画折叠项目,折叠完成后,我从列表视图中删除项目(通过从数据列表中删除项目并调用notifyDataSetChanged)。为了检测动画是否完成,我检查applyTransformation方法中的interpolatedTime==1.0。问题是,`interpolatedTime'==1时调用了两次applyTransformation,因此我不能真正依赖它(否则我可以删除两个项而不是一个项)。为什么会这样?以下是我的一些代码: pub

我有一个
列表视图
,其项目需要用动画折叠,然后删除。我使用
动画
折叠项目,折叠完成后,我从
列表视图
中删除项目(通过从数据列表中删除项目并调用
notifyDataSetChanged
)。为了检测动画是否完成,我检查
applyTransformation
方法中的
interpolatedTime
==1.0。问题是,`interpolatedTime'==1时调用了两次
applyTransformation
,因此我不能真正依赖它(否则我可以删除两个项而不是一个项)。为什么会这样?以下是我的一些代码:

public static void collapseAndDelete(final View v, final ArrayList<AlarmClock> alarmClockArrayList,
                                     final AlarmsArrayAdapter adapter, final int position) {
    final int initialHeight = v.getMeasuredHeight();
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            if (interpolatedTime == 1) {
                alarmClockArrayList.remove(position);
                adapter.notifyDataSetChanged();
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.requestLayout();
                v.setAlpha(1.0f - interpolatedTime);
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };
    a.setDuration(400);
    v.startAnimation(a);
}
public static void collapseAndelete(最终视图v,最终ArrayList alarmClockArrayList,
最终报警(RAY适配器,最终int位置){
最终int initialHeight=v.getMeasuredHeight();
动画a=新动画(){
@凌驾
受保护的无效应用转换(浮点插值时间,转换t){
如果(插值时间==1){
alarmClockArrayList.移除(位置);
adapter.notifyDataSetChanged();
}否则{
v、 getLayoutParams().height=initialHeight-(int)(initialHeight*interpolatedTime);
v、 requestLayout();
v、 setAlpha(1.0f-插值时间);
}
}
@凌驾
公共布尔值willChangeBounds(){
返回true;
}
};
a、 设定持续时间(400);
v、 startAnimation(a);
}

实现动画侦听器以捕获最终回调

r.setAnimationListener(new OAnimationListener(this));
课程示例:

public class OAnimationListener implements AnimationListener{

    private MyView vv;


    public OAnimationListener(MyView vv) {
        // TODO Auto-generated constructor stub
        this.vv = vv;
    }

    @Override
    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onAnimationEnd(Animation animation) {
        if (vv != null)
            vv.stopAnim(2); //or any wanted callback

    }
}
别忘了设置此选项:

r.setRepeatCount(0);

                r.setFillAfter(true);

很有效,谢谢!虽然我很想知道我为什么会有问题,但有什么解释吗?@ulmaxy,我想可能会出现,例如,在使用
r.setFillAfter(true)时。但实际上我不知道。我得看看你的全部代码。此外,根据供应商的不同,有不同的回调实现。我有完全相同的问题,并使用
a.setAnimationListener(listener)解决了它