2012-09-13 6 views
13

私はGoogle+アプリで投稿をスクロールするときに発生するアニメーションが好きですが、達成方法を理解できません。GoogleはどのようにG +アプリでアニメーション投稿を達成していますか?

投稿が表示されているときに投稿をアニメーション化するためにどのような手法が採用されていますか?アニメーションそのものを探しているわけではなく、スクロール可能なアイテムのリストにアニメーションを適用する方法です

ありがとうございました。

+0

はありません[この](http://stackoverflow.com/questions/6850490/how-does-scrolling-work-in- the-google-android-app)は役に立ちますか? – cosmincalistru

+0

@cosmincalistruそれは別の質問です、そうではありません。 – Glitch

答えて

10

いくつかのテストの後、私は仕事に似た何かを得たと思う。

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    final LinearLayout list = new LinearLayout(this); 
    list.setOrientation(LinearLayout.VERTICAL); 

    ScrollView scrollView = new ScrollView(this) { 
     Rect mRect = new Rect(); 

     @Override 
     public void onLayout(boolean changed, int l, int t, int r, int b) { 
      super.onLayout(changed, l, t, r, b); 

      for (int i = 0; i < list.getChildCount(); ++i) { 
       View v = list.getChildAt(i); 

       // Tag initially visible Views as 'true'. 
       mRect.set(l, t, r, b); 
       v.setTag(getChildVisibleRect(v, mRect, null));     
      } 
     } 

     @Override 
     public void onScrollChanged(int l, int t, int oldl, int oldt) { 
      super.onScrollChanged(l, t, oldl, oldt); 

      for (int i = 0; i < list.getChildCount(); ++i) { 
       View v = list.getChildAt(i); 
       mRect.set(getLeft(), getTop(), getRight(), getBottom()); 

       // If tag == 'false' and View is visible we know that 
       // View became visible during this scroll event. 
       if ((Boolean) v.getTag() == false 
         && getChildVisibleRect(v, mRect, null)) { 
        AlphaAnimation anim = new AlphaAnimation(0, 1); 
        anim.setDuration(1000); 
        v.startAnimation(anim); 
        v.setTag(true); 
       } 
      } 
     } 
    }; 
    scrollView.addView(list); 

    for (int i = 0; i < 20; ++i) { 
     TextView tv = new TextView(this); 
     tv.setText("Test"); 
     tv.setTextSize(72); 
     tv.setTextColor(Color.WHITE); 
     tv.setBackgroundColor(Color.GRAY); 
     list.addView(tv); 
    } 

    setContentView(scrollView); 
} 

リストを下にスクロールすると、一度新しいTextView sが見えるようになり、アルファアニメーションをトリガする必要があります。そのためのライブラリがあります

+0

ありがとう、これは動作するようです!私は 'v.setAnimation(anim)'を '' v.startAnimation(anim) 'に置き換えなければなりませんでした。そうでなければアニメーション化されませんでした。 – Glitch

+0

効率はどれくらいですか?アンドロイドがアイテムのリストをスクロールするためにListViewを使用するように指定している理由があります – jonney

関連する問題