1

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!

Hans1984
  • 796
  • 11
  • 24
Neha Shukla
  • 3,572
  • 5
  • 38
  • 69
  • use this link http://www.androidhive.info/2013/06/android-working-with-xml-animations/ – Mayank Sugandhi Jun 23 '15 at 08:35
  • in `getVIew()` start any animation you want give some delay so that item will show after that much of time – N J Jun 23 '15 at 08:35
  • 1
    @Mayank I am already following this link, but didnot get desired output, using this items are adding all together – Neha Shukla Jun 23 '15 at 08:37
  • 1
    @androicode :- I think Nilesh is right , if you want to add element one by one with animation then you have to implement code in getview of animation, which type animation do you want? – Mayank Sugandhi Jun 23 '15 at 08:41

5 Answers5

2

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);
Neha Shukla
  • 3,572
  • 5
  • 38
  • 69
1

you can try the class LayoutAnimationController

lypeer
  • 30
  • 4
1

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.

Community
  • 1
  • 1
Malvin
  • 692
  • 5
  • 8
1

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;
}
Aman Arora BB
  • 190
  • 1
  • 12
1

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;


}
narancs
  • 5,234
  • 4
  • 41
  • 60