【问题标题】:How do I animate (slide in) a RecyclerView's item's entrance?如何为 RecyclerView 项目入口设置动画(滑入)?
【发布时间】:2015-10-16 19:55:36
【问题描述】:

基本上我想要this (at the 30 second mark)之类的东西

我希望我的项目在活动开始后按顺序滑入。

我试过谷歌搜索。我没有发现任何我能理解的东西。在这个为 Android 开发应用程序的疯狂世界中,我仍在摸索。

谢谢。

【问题讨论】:

标签: android android-recyclerview


【解决方案1】:

像这样在recyclerView上添加动画

recyclerView = (RecyclerView) findViewById(R.id.rv);
        recyclerView.setHasFixedSize(true);
        llm = new LinearLayoutManager(getApplicationContext());
        recyclerView.setLayoutManager(llm);

        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(100);
        set.addAnimation(animation);

        controller = new LayoutAnimationController(set, 0.5f);

        adapter = new RecycleViewAdapter(poetNameSetGets, this);
        recyclerView.setLayoutAnimation(controller);

【讨论】:

  • 这应该是选择的答案!
  • 你知道当我从recyclerview清除所有数据时如何使用那个动画吗?
【解决方案2】:

您需要在 RecyclerView 的 Adapter onBindViewHolder 方法中运行动画。

@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
    runEnterAnimation(viewHolder.itemView);
}

private void runEnterAnimation(View view) {
        view.setTranslationY(Utils.getScreenHeight(context));
        view.animate()
                .translationY(0)
                .setInterpolator(new DecelerateInterpolator(3.f))
                .setDuration(700)
                .start();
    }
}

更多信息在这里http://frogermcs.github.io/Instagram-with-Material-Design-concept-is-getting-real/(查看FeedAdapter)

【讨论】:

  • 您需要为 setTranslationY 提供屏幕高度。在这里查看身高stackoverflow.com/questions/1016896/…
  • 效果很好。不过还有一件事。如何按顺序制作动画?
  • 他们现在不是按顺序制作动画吗?因为他们应该这样做。
  • 他们不是。所有项目同时滑入。
  • 无法在cmets中给你详细的答案。发布另一个问题。
猜你喜欢
  • 2016-11-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多