2015-10-16 38 views
5

基本上我想要的东西像this (at the 30 second mark)如何动画(滑入)RecyclerView的物品入口?

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

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

谢谢。

+0

404找不到网页....你的链接 –

+0

@AmarbirSingh我编辑他的职位但他还没有批准。无论如何,这里是他正在谈论的链接https://www.youtube.com/watch?v=Q8TXgCzxEnw#t=30。 –

+0

@Amarbir对不起。我已经编辑了链接。 –

回答

3

您需要在RecyclerView的适配器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)

+0

“无法解析符号Utils”。这是为什么? –

+0

您需要提供屏幕高度的setTranslationY。检查这里获取高度http://stackoverflow.com/questions/1016896/get-screen-dimensions-in-pixels – HellCat2405

+0

伟大的作品。还有一件事。我如何依次对它们进行动画制作? –

13

上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); 
+0

这应该是选定的答案! –

+0

您是否知道在清除回收站视图中的所有数据时如何使用该动画? –