I saw in one application that there was a GridView
in which items were getting added one by one (not all at the same time).
I am looking for that animation.
Can someone please help me?
Thanks!
I saw in one application that there was a GridView
in which items were getting added one by one (not all at the same time).
I am looking for that animation.
Can someone please help me?
Thanks!
getting hint from answer below my question about LayoutAnimationController
, I am able to achieve the output as I wanted in my answer.
Below I am posting my code:
My animation class
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(500);
set.addAnimation(animation);
animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f
);
animation.setDuration(500);
set.addAnimation(animation);
LayoutAnimationController controller =
new LayoutAnimationController(set, 0.5f);
And I set it in my GridView as
gridView.setLayoutAnimation(controller);
you can try the class LayoutAnimationController
Use RecyclerView
which can be found in AppCompat Support Library
And then subclass RecyclerView.ItemAnimator
and pass it as a parameter to RecyclerView.setItemAnimator
Some examples can be found here and here
Note: to use RecyclerView
as a grid, you need to use RecyclerView.setLayoutManager
and pass GridLayoutManager
as the argument.
Hope this helps.
Try to add animation to your adapter in getview method like this:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null)
{
LayoutInflater inflator = LayoutInflater.from(context);
convertView = inflator.inflate(R.layout.grid_view, null);
}
convertView.setAnimation(animation)
return convertView;
}
The view is returning in the getView method of the adapter. So you have to add you animation to your view, here. Please see my code for you:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder vh;
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.gridview_item, null);
vh = new ViewHolder();
vh.iw = (ImageView) convertView.findViewById(R.id.iw);
vh.container = (RelativeLayout) convertView.findViewById(R.id.category_label);
vh.cateoryIcon = (ImageView) convertView.findViewById(R.id.category_icon);
vh.username = (TextView) convertView.findViewById(R.id.username);
vh.userScore = (TextView) convertView.findViewById(R.id.user_picture_score);
vh.progressbar = new ProgressBar(context);
convertView.setTag(vh);
} else {
vh = (ViewHolder) convertView.getTag();
}
UserHelper user = userList.get(position);
vh.iw.setAdjustViewBounds(true);
vh.container.setBackgroundColor(Color.parseColor(CategoryManager.INSTANCE.getCategoryById(user.getCategoryId()).getColorTransparent()));
vh.cateoryIcon.setImageBitmap(CategoryManager.INSTANCE.getCategoryById(user.getCategoryId()).getSmallIcon());
vh.username.setText(user.getNickName());
vh.userScore.setText(user.getScore());
Animation animation;
if (position % 4 == 0) {
animation = AnimationUtils.loadAnimation(context, R.anim.your_sexy_animation);
animation.setDuration(340);
} else {
animation = AnimationUtils.loadAnimation(context, R.anim.fade_in);
animation.setDuration(280);
}
convertView.startAnimation(animation);
imageLoader.displayImage(user.getImageUrl(), vh.iw);
return convertView;
}