Android 如何应用动画在gridview中逐个添加项目

Android 如何应用动画在gridview中逐个添加项目,android,animation,Android,Animation,我在一个应用程序中看到有一个GridView,其中一个项目一个项目地添加,而不是同时添加所有项目 我在找那个动画 有人能帮我吗 谢谢 您可以尝试类LayoutImationController您可以尝试类LayoutImationController使用可在中找到的RecyclerView 然后创建子类并将其作为参数传递给RecyclerView.setItemAnimator 可以找到一些例子并加以说明 注意:要将RecyclerView用作网格,需要使用RecyclerView.setLay

我在一个应用程序中看到有一个GridView,其中一个项目一个项目地添加,而不是同时添加所有项目

我在找那个动画

有人能帮我吗


谢谢

您可以尝试类LayoutImationController

您可以尝试类LayoutImationController

使用可在中找到的RecyclerView

然后创建子类并将其作为参数传递给RecyclerView.setItemAnimator

可以找到一些例子并加以说明

注意:要将RecyclerView用作网格,需要使用RecyclerView.setLayoutManager并将其作为参数传递

希望这有帮助。

使用可在中找到的RecyclerView

然后创建子类并将其作为参数传递给RecyclerView.setItemAnimator

可以找到一些例子并加以说明

注意:要将RecyclerView用作网格,需要使用RecyclerView.setLayoutManager并将其作为参数传递


希望这有帮助。

尝试在getview方法中向适配器添加动画,如下所示:

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

尝试在getview方法中将动画添加到适配器,如下所示:

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

视图正在适配器的getView方法中返回。因此,您必须在此处将动画添加到视图中。请查看我的代码:

   @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;


}

视图正在适配器的getView方法中返回。因此,您必须在此处将动画添加到视图中。请查看我的代码:

   @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;


}

从下面关于LayoutImationController的问题的答案中得到提示,我能够实现我在答案中想要的输出

下面是我的代码:

我的动画课

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);
我在GridView中将其设置为

gridView.setLayoutAnimation(controller);

从下面关于LayoutImationController的问题的答案中得到提示,我能够实现我在答案中想要的输出

下面是我的代码:

我的动画课

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);
我在GridView中将其设置为

gridView.setLayoutAnimation(controller);

在getVIew中使用此链接启动您想要的任何动画,并给予一定的延迟,以便该项目将在播放了大量动画后显示time@Mayank我已经在关注这个链接,但没有得到想要的输出,使用这个项目正在添加所有together@androicode:-我认为尼利斯是对的,如果您想在动画中逐个添加元素,那么您必须在getview of animation中实现代码,您想要哪种类型的动画?在getview中使用此链接启动您想要的任何动画,并给予一定的延迟,以便该项目将在该动画之后显示time@Mayank我已经在关注这个链接,但是没有得到想要的输出,使用此选项可以添加所有项目together@androicode:-我认为Nilesh是对的,如果你想在动画中逐个添加元素,那么你必须在动画的getview中实现代码,你想要哪种类型的动画?请告诉我,如果我们使用控制器的SetLayoutImation,那么我们如何停止这个动画?请添加示例代码和源代码,这不是答案。请告诉我,如果我们对控制器使用SetLayoutImation,那么如何停止此动画?请添加示例代码和源代码,这不是答案。