繁体   English   中英

如何设置(滑入)RecyclerView项目的入口动画?

[英]How do I animate (slide in) a RecyclerView's item's entrance?

基本上我想要这样的东西(在30秒标记处)

一旦活动开始,我希望我的项目顺序滑动。

我试过谷歌搜索。 我找不到任何我能理解的东西。 我仍然在开发这个为Android开发应用程序的疯狂世界。

谢谢。

像这样在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的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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM