在开始的ListView项目AnimationDrawable。当项目连接? [英] Starting AnimationDrawable in ListView items. When are the items attached?

查看:251
本文介绍了在开始的ListView项目AnimationDrawable。当项目连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我一直在做一些阅读在过去的几个小时,我的理解是调用start()上绘制对象/ ImageView的完全连接将无法启动动画之前AnimationDrawable。这似乎是pretty与通常的UI初始化过程(如添加视图后立即返回视图的尺寸为0)相一致。

So I've been doing some reading for the past few hours and I understand that calling start() on an AnimationDrawable before the Drawable/ImageView is fully attached will not start the animation. This seems pretty consistent with the usual UI initialization process (like view's dimensions being returned as 0 right after adding the view).

我想,同样的问题是错误的,当我尝试从一个适配器的getView()方法,启动动画。使用延迟Runnable的执行开始()调用解决了这个问题,但显然不是一个理想的解决方案。

I imagine that this same issue is at fault when I try to start the animation from the getView() method of an Adapter. Using a delayed Runnable that performs the start() call solves this problem but is clearly not a desirable solution.

有没有办法接受一个回调,一旦ListView的项目为完全附着?

Is there any way to receive a callback once ListView's items are "fully attached"?

推荐答案

据该的文档,必须在启动动画前等待查看连接到窗口。为此,你应该增加一个 OnAttachStateChangeListener 来,将执行时,它已经连接,并从那里开始动画的看法。

According to the documentation, you must wait until the View is attached to the window before starting animation. Therefor, you should add an OnAttachStateChangeListener to the view that will execute when it has been attached, and start the animation from there.

ImageView loadingImg = (ImageView)v.findViewById(R.id.image);
loadingImg.setBackgroundResource(R.drawable.progressdialog);
loadingImg.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
  @Override
  public void onViewAttachedToWindow(View v) {
    AnimationDrawable loadingAnimation = (AnimationDrawable) v.getBackground();
    loadingAnimation.start();
  }

  @Override
  public void onViewDetachedFromWindow(View v) {
  }
});

我试着开始在的Runnable 动画中的查看后()方法,并没有奏效。以上方法是我一直可靠有一个的ListView动画开始的唯一途径

I've tried starting the animation in a Runnable in the View's post() method, and that didn't work. The above method is the only way I've reliably been to have animation start in a ListView.

这篇关于在开始的ListView项目AnimationDrawable。当项目连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆