如何在列表视图中显示淡入效果的图像?

时间:2016-02-25 17:14:43

标签: android imageview

如何在列表视图中显示具有淡入淡出效果的图像(我不知道确切的名称),就像应用程序中的yummly一样。 https://play.google.com/store/apps/details?id=com.yummly.android 对这些库或有用资源的任何引用?

1 个答案:

答案 0 :(得分:1)

您可以使用此示例

在适配器中(扩展BaseAdapter或ArrayAdapter):

private int lastPosition = -1;

@Override
public View getView(int position, View convertView, ViewGroup parent) {
  //.....inflating and bind view

  setAnimation(convertView, position);
  return convertView;
}


 /**
 * Here is the key method to apply the animation
 */
private void setAnimation(View viewToAnimate, int position) {
    // If the bound view wasn't previously displayed on screen, it's animated
    if (position > lastPosition) {
        Animation animation = AnimationUtils.loadAnimation(mContext, android.R.anim.fade_in);
        viewToAnimate.startAnimation(animation);
        lastPosition = position;
    }
}

或者对于RecyclerView.Adapter:

@Override
public void onBindViewHolder(final HistoryHolder holder, final int position) {
....
setAnimation(holder.animatedView, position);
}