我使用自定义列表视图来显示项目列表,每个项目都是我的对象的实例,上面有一个按钮。我为某个项的按钮设置了ValueAnimator,其属性为isAnim = true。看起来没问题,但是当我向下滚动列表视图时,其中一些项目是' isAnim = false'还有动画。 这是我的代码动画:
protected void blinkblinkImage(Button bt) {
ValueAnimator colorAnim = ObjectAnimator.ofInt(bt, "textColor", activity.getResources().getColor(R.color.white),
activity.getResources().getColor(R.color.cam),
activity.getResources().getColor(R.color.blue1),
activity.getResources().getColor(R.color.red),
activity.getResources().getColor(R.color.yellow));
colorAnim.setDuration(300);
colorAnim.setEvaluator(new ArgbEvaluator());
colorAnim.setRepeatCount(ValueAnimator.INFINITE);
colorAnim.setRepeatMode(ValueAnimator.REVERSE);
colorAnim.start();
}
这里是为项目设置动画
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
if(convertView == null)
view = inflater.inflate(R.layout.item_xe, null);
final Button btTT = (Button) view.findViewById(R.id.bt_tt);
final HashMap<String, String> itemxe = data.get(position);
final Boolean isAnim = itemxe.get(Login_Activity.TAG_ANIM);
if(isAnim)
blinkblinkImage(btTT);
return view;
}
答案 0 :(得分:0)
尝试以下代码:
protected void blinkblinkImage(Button bt) {
ValueAnimator colorAnim = ObjectAnimator.ofInt(bt, "textColor", activity.getResources().getColor(R.color.white),
activity.getResources().getColor(R.color.cam),
activity.getResources().getColor(R.color.blue1),
activity.getResources().getColor(R.color.red),
activity.getResources().getColor(R.color.yellow));
bt.setHasTransientState(true);
colorAnim.setDuration(300);
colorAnim.setEvaluator(new ArgbEvaluator());
colorAnim.setRepeatCount(ValueAnimator.INFINITE);
colorAnim.setRepeatMode(ValueAnimator.REVERSE);
colorAnim.addListener(new AnimatorListenerAdapter{
@Overrid
public void onAnimationEnd(Animator animation){
bt.setHasTransientState(false);
}
});
colorAnim.start();
}