
@OverrIDe public VIEw getVIEw(int position,VIEw convertVIEw,VIEwGroup parent) { if (convertVIEw == null) { LayoutInflater inflater = LayoutInflater.from(context); convertVIEw = inflater.inflate(resource,parent,false); holder = new VIEwHolder(); holder.newRoomVIEw = (TextVIEw) convertVIEw.findVIEwByID(R.ID.newRoom); convertVIEw.setTag(holder); } else { holder = (VIEwHolder) convertVIEw.getTag(); } Room item = items.get(position); // animate new rooms if (item.isNewRoom()) { AlphaAnimation AlphaAnim = new AlphaAnimation(1.0f,0.0f); AlphaAnim.setDuration(1500); AlphaAnim.setAnimationListener(new AnimationListener() { public voID onAnimationEnd(Animation animation) { holder.newRoomVIEw.setVisibility(VIEw.INVISIBLE); } @OverrIDe public voID onAnimationStart(Animation animation) {} @OverrIDe public voID onAnimationRepeat(Animation animation) {} }); holder.newRoomVIEw.startAnimation(AlphaAnim); } // ... return convertVIEw; } 在适配器外面添加一个新房间并调用notifyDataSetChanged新房间是正确的动画,但是当onAnimationEnd被调用时,另一个(不是新的房间)被隐藏.
有什么办法可以隐藏正确的房间吗?
解决方法 由于您尚未在getVIEw()方法中声明持有人变量,我只能假设您已将其声明为类中的实例变量.这是你的问题.在动画完成时,变量持有人持有对完全不同的项目的引用.您需要使用在getVIEw()方法中声明为final的局部变量.我不知道在getVIEw()方法之外是否需要这个持有者变量,但如果你这样做,你可以这样做:
// animate new rooms if (item.isNewRoom()) { final VIEwHolder holdercopy = holder; // make a copy AlphaAnimation AlphaAnim = new AlphaAnimation(1.0f,0.0f); AlphaAnim.setDuration(1500); AlphaAnim.setAnimationListener(new AnimationListener() { public voID onAnimationEnd(Animation animation) { holdercopy.newRoomVIEw.setVisibility(VIEw.INVISIBLE); } @OverrIDe public voID onAnimationStart(Animation animation) {} @OverrIDe public voID onAnimationRepeat(Animation animation) {} }); holder.newRoomVIEw.startAnimation(AlphaAnim); } 这当然是不行的,如果动画需要这么长的时间,视图已被回收利用在此期间.
总结以上是内存溢出为你收集整理的android – 使用ViewHolder模式的适配器中的动画全部内容,希望文章能够帮你解决android – 使用ViewHolder模式的适配器中的动画所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)