2017-10-17 81 views
0

如何使從當前位置到在列表視圖Android其它用戶選擇的位置移動動畫,如何使從當前位置到列表視圖中的其他選定位置移動動畫?

在我的列表視圖,我想在其中用戶選擇的位置的動畫(currentPosition = 5)。 以後如果用戶將改變選擇的位置(currentPosition = 8,一位置= 5)

我需要動畫等:從一位置(5)〜currentPosition(8)的ImageView的拖動(從第五位置到第八位置移動或者(如果用戶改變位置的ImageView從第八位置移動到第10位) 請問有什麼可以做呢?

我沒有發現正是我要找的,從這個
但除此之外,我發現從谷歌的鏈接(Zooming in a view),這將從currentPosition中縮放imageView,但它不是我正在尋找的。

請幫忙。

+0

這將是**簡單得多**如果你使用'RecyclerView'和'(如,它在默認情況下做到這一點) DiffCallback'。如果你正在嘗試做一個非常簡單的列表,不要使用ListView。 – CommonsWare

+0

@CommonsWare你能解釋一些更多。究竟如何? 是的,我正在使用recyclerView。 – Dhiren

+0

「是的,我正在使用recyclerView」 - 不是根據你的問題。我很抱歉,班級是'DiffUtil',而不是'DiffCallback'。請參閱[JavaDocs](https://developer.android.com/reference/android/support/v7/util/DiffUtil.html),[此Caster.IO介紹](https://caster.io/lessons/recyclerview -animate-complex-content-changes-with-diffutil /),[this Medium post](https://medium.com/@gabornovak/use-diffutil-for-out-of-the-box-animations-d932a28d6229)等 – CommonsWare

回答

0

使用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); 
     } 
+0

我不想在這裏移動一個項目,我只是想動畫imageView,從lastPosition到currentPosition。 – Dhiren

相關問題