I want to animate ListView items when they first appear. I have the following viewholder:
public class SimpleViewHolder extends RecyclerView.ViewHolder
{
private TextView simpleTextView;
public SimpleViewHolder(final View itemView, final SimpleAdapter.onItemClickListener listener)
{
super(itemView);
simpleTextView = (TextView) itemView.findViewById(R.id.simple_text);
RotateAnimation rotate = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
rotate.setDuration(1000);
rotate.setRepeatCount( 0 );
simpleTextView.setAnimation(rotate);
}
public void bindData(final SimpleViewModel viewModel)
{
simpleTextView.setText( viewModel.getSimpleText() );
}
}
Everything works great, except instead of setting the animations programmatically, I would like to load them from an XML file using the following method:
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.myanimation);
But I'm not clear how to get/pass the context to the RecyclerView.ViewHolder or is this even the proper place where to do animations.
How can I load the XML animation within the RecyclerView.ViewHolder and is this correct place for doing animations for the list items? Thanks!