【问题标题】:How does Google achieve animated posts in their G+ app?Google 如何在其 G+ 应用中实现动画帖子?
【发布时间】:2012-09-13 15:51:52
【问题描述】:

我喜欢滚动浏览 Google+ 应用中的帖子时出现的动画,但我不知道它们是如何实现的。

在帖子出现时采用了哪些技术来为帖子设置动画?我不是在寻找动画本身,而是如何将任何动画应用于可滚动项目列表。

谢谢。

【问题讨论】:

  • this 有帮助吗?
  • @cosmincalistru 这是一个不同的问题,所以没有。

标签: android google-plus


【解决方案1】:

经过一些测试,我认为我得到了类似工作的东西;

@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);
}

一旦新的TextViews 变得可见,向下滚动列表应该会触发 alpha 动画。

【讨论】:

  • 谢谢,这似乎有效!我不得不用`v.startAnimation(anim)替换v.setAnimation(anim),否则它不会动画。
  • 效率如何? android 指定我们使用 ListView 滚动项目列表是有原因的
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多