gpt4 book ai didi

Android ListView 项目动画 - 仅对第一个可见项目进行动画处理

转载 作者:太空狗 更新时间:2023-10-29 15:52:50 25 4
gpt4 key购买 nike

我正在尝试重现此 ListView 项目:

http://material-design.storage.googleapis.com/videos/components-progressandactivity-progressandactivity-2-drive.mobile-load.folders_large_xhdpi.webm

我已经用这些代码行成功地实现了它(不包括动画 xml 文件):

//Set animation
if(position > lastAnimPosition){
lastAnimPosition = position;

Animation anim = AnimationUtils.loadAnimation(context, R.anim.item_slide_in);
anim.setStartOffset(50 * position);
row.startAnimation(anim);
}

所以动画很好,但是当我向下滚动时,存在偏移问题 - 它太大了,让人觉得应用程序加载项目的时间太长了。 我需要做的是找出何时应该禁用偏移 - 或者如何只为首次显示的项目启用偏移。

最佳答案

在你的xml中使用布局动画属性

此处的文档:http://developer.android.com/reference/android/view/ViewGroup.html#attr_android:layoutAnimation

将文件添加到 layout_item_slide_in.xml 的 res/anim 文件夹中,该文件引用了 @anim/item_slide_in

<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:delay="0.5"
android:animation="@anim/item_slide_in" />

现在,稍微更改您的 listview xml 以包含 android:layoutAnimation 属性和值

<ListView
android:id="@+id/foo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutAnimation="@anim/layout_item_slide_in"" />

这将实现您想要的相同的首次加载动画样式,而无需在代码中完成

关于Android ListView 项目动画 - 仅对第一个可见项目进行动画处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27277671/

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