gpt4 book ai didi

android - Google 如何在他们的 G+ 应用程序中实现动画帖子?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:25:07 24 4
gpt4 key购买 nike

我喜欢在 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 动画。

关于android - Google 如何在他们的 G+ 应用程序中实现动画帖子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12410187/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com