2015-10-16 44 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

您是否知道在清除回收站視圖中的所有數據時如何使用該動畫? –