【问题标题】:How to make a listview entry blink after scrolling to it?滚动到列表视图条目后如何使其闪烁?
【发布时间】:2019-07-18 22:47:43
【问题描述】:

我的应用程序中有一个列表视图,我希望能够滚动到列表视图中的某个位置,然后在该条目处执行闪烁动画以向用户突出显示它。

我遇到的问题是,如果滚动到的条目位于列表视图的视图之外,则不会发生闪烁动画。我知道列表视图很有效,因为它不会一次加载所有条目,所以这可能是动画没有发生的原因。我该如何解决这个问题?

滚动到代码:

    //Changes to tab with listview
    tabLayout.getTabAt(1).select();
    //Get index to scroll to
    int selectIndex = whitelistFragment.getWhitelistTableHelper().getListViewEntryIndex(entryString);
    //If the entry exists
    if(selectIndex != -1) {
        //Scroll to index
        whitelistFragment.getWhitelistTableHelper().getListView().setSelection(selectIndex);

        //Make entry blink several times
        View entryView = helperFunctions.getViewByPosition(selectIndex, whitelistFragment.getWhitelistTableHelper().getListView());
        Animation blinkAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink);
        entryView.startAnimation(blinkAnimation);
    }

Blink.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="600"
        android:repeatMode="reverse"
        android:repeatCount="5"/>
</set>

【问题讨论】:

    标签: android android-listview android-animation


    【解决方案1】:

    ListView 效率不高,应该使用RecyclerView。它有方法 scrollToPosition()。稍后在 onBindViewHolder 检查 position == blink position 并在 itemView 上运行动画。您可以使用 startDelay 以获得更好的外观。

    【讨论】:

    • 我宁愿不重构我的代码以使用 RecyclerView,这样我就可以做一个简单的闪烁动画。没有我可以使用的解决方法吗?
    • 我实际上实现了一个 ScrollListener 并在滚动完成后执行动画,现在它可以工作了。
    • 您的清单中有多少项? RecyclerView 是非常棒的视图,具有出色的性能,并且很容易迁移到它。
    猜你喜欢
    • 2010-11-17
    • 1970-01-01
    • 2011-09-06
    • 1970-01-01
    • 1970-01-01
    • 2020-03-04
    • 2020-08-27
    • 1970-01-01
    • 2015-10-18
    相关资源
    最近更新 更多