【问题标题】:How to make move animation from current position to other selected position in listview?如何将动画从当前位置移动到列表视图中的其他选定位置?
【发布时间】:2017-10-17 12:30:03
【问题描述】:

如何在listview android中将动画从当前位置移动到其他用户选择的位置,

在我的列表视图中,我想制作一个动画,让用户在其中选择一个位置(currentPosition=5)。 稍后如果用户将更改选择一个位置 (currentPosition=8,lastPosition=5)

我需要像这样的动画:从 lastPosition(5) 到 currentPosition(8) 一个 imageView 拖动(从第 5 个位置移动到第 8 个位置或(如果用户更改位置 imageView 从第 8 个位置移动到第 10 个位置) 我该怎么做?

我没有找到我要找的东西,
但除此之外,我从谷歌找到了一个链接(Zooming in a view),这将从 currentPosition 缩放图像视图,但这不是我想要的。

请帮忙。

【问题讨论】:

  • 如果您使用RecyclerViewDiffCallback,这将简单得多(默认情况下它会这样做)。如果您尝试做的不是相当简单的列表,请不要使用ListView
  • @CommonsWare 你能解释一下吗?究竟如何?是的,我正在使用 recyclerView。
  • “是的,我正在使用 recyclerView”——不是根据你的问题。抱歉,课程是DiffUtil,而不是DiffCallback。见the JavaDocsthis Caster.IO presentationthis Medium post
  • 您能否提供代码,它是如何使用 DiffUtil 工作的
  • 我在之前的评论中链接到资源。如果您不了解它们所呈现的内容,并且您无法使用搜索引擎找到其他资源,请提出一个单独的 Stack Overflow 问题,您可以在其中解释您尝试了什么以及遇到了哪些具体问题。

标签: android android-layout listview android-animation


【解决方案1】:

使用 RecyclerView 可以直接从一个位置移动到另一个位置

/**
         * Notify any registered observers that the item reflected at <code>fromPosition</code>
         * has been moved to <code>toPosition</code>.
         *
         * <p>This is a structural change event. Representations of other existing items in the
         * data set are still considered up to date and will not be rebound, though their
         * positions may be altered.</p>
         *
         * @param fromPosition Previous position of the item.
         * @param toPosition New position of the item.
         */
        public final void notifyItemMoved(int fromPosition, int toPosition) {
            mObservable.notifyItemMoved(fromPosition, toPosition);
        }

【讨论】:

  • 我不想在这里移动一个项目,我只是想动画imageView,从lastPosition到currentPosition。
猜你喜欢
  • 2013-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多