gpt4 book ai didi

android - ArrayAdapter 的动画延迟加载

转载 作者:行者123 更新时间:2023-11-30 03:37:16 27 4
gpt4 key购买 nike

您好,我正在为 ArrayAdapter 使用动画。我想在加载缩略图时对其进行动画处理......但是每次加载列表的任何缩略图时,动画都会为数组适配器的每个项目启动。结果,每个缩略图的动画开始了 5 次。我必须怎么做才能防止在加载任何项目时启动动画?

public View getView(int position, View item, ViewGroup parent){

ViewHolder holder;
Video video = mVideoList.get(position);

if(item == null)
{
item = mInflater.inflate(R.layout.adapter_recommended_videos, null);

holder = new ViewHolder();
holder.title = (TextView)item.findViewById(R.id.adapter_recommended_videos_textview);
holder.thumb = (ImageView)item.findViewById(R.id.adapter_recommended_videos_imageview);

holder.title.setTypeface(
Typeface.createFromAsset(mContext.getAssets(), "roboto_medium.ttf"));

item.setTag(holder);
}
else
{
holder = (ViewHolder) item.getTag();

}

holder.title.setText(video.getTitle());
ImageView iv = holder.thumb;
if (video.getThumb() != null) {
if(!mAnimationFlags.get(position)){
iv.startAnimation(mAnimation);
mAnimationFlags.set(position, true);
}
holder.thumb.setImageBitmap(video.getThumb());
} else {
holder.thumb.setImageResource(R.drawable.dummy_video_thumbnail);
}


return(item);
}


static class ViewHolder {
TextView title;
ImageView thumb;
}

最佳答案

没关系,我自己解决了,我只需要在每次调用“getView()”时实例化一个新动画。这是正确的代码:

public View getView(int position, View item, ViewGroup parent){

ViewHolder holder;
Video video = mVideoList.get(position);

if(item == null)
{
item = mInflater.inflate(R.layout.adapter_recommended_videos, null);

holder = new ViewHolder();
holder.title = (TextView)item.findViewById(R.id.adapter_recommended_videos_textview);
holder.thumb = (ImageView)item.findViewById(R.id.adapter_recommended_videos_imageview);

holder.title.setTypeface(
Typeface.createFromAsset(mContext.getAssets(), "roboto_medium.ttf"));

item.setTag(holder);
}
else
{
holder = (ViewHolder) item.getTag();

}

holder.title.setText(video.getTitle());
ImageView iv = holder.thumb;
if (video.getThumb() != null) {
if(!mAnimationFlags.get(position)){
Animation anim = AnimationUtils.loadAnimation(mContext, android.R.anim.fade_in);
iv.startAnimation(anim);
mAnimationFlags.set(position, true);
}
holder.thumb.setImageBitmap(video.getThumb());
} else {
holder.thumb.setImageResource(R.drawable.dummy_video_thumbnail);
}


return(item);
}

关于android - ArrayAdapter 的动画延迟加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16472164/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com