繁体   English   中英

Google如何在他们的G +应用中获得动画帖子?

[英]How does Google achieve animated posts in their G+ app?

我喜欢滚动浏览Google+应用中的帖子时出现的动画,但我无法弄清楚他们是如何实现的。

当它们出现时,会采用什么技术来制作帖子? 我不是在寻找动画本身,而是我如何将任何动画应用于可滚动项目列表。

谢谢。

经过一些测试后,我觉得我有类似工作的东西;

@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变为可见时触发alpha动画。

有一个库,它似乎做得很好: https//github.com/cuub/sugared-list-animations

暂无
暂无

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

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