2016-02-25 60 views

回答

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); 
}