是否可以爲expandableListView應用展開或摺疊動畫?animation for expandableListView
回答
可以使用包含最初隱藏視圖的簡單ListView和擴展Animation的自定義類來完成。 基本思路是從View.GONE
開始,然後逐漸將邊距從負值重新調整爲所需的大小,同時將可見性設置爲View.VISIBLE
。
參見:
- https://github.com/tjerkw/Android-SlideExpandableListView
- Android Animation: Hide/Show Menu
- How do I animate View.setVisibility(GONE)
..和最後
最後一個例子包含您需要的所有代碼。它對我來說看起來有些ha especially,特別是你必須首先設置view.bottomMargin = -50
或更多,否則動畫第一次不能正常工作,但到目前爲止我沒有找到任何可行的替代方法(除了使用自己的ScrollView容器項而不是ListView)。
最後,這個程序包括上面的例子中,很多的鏈接其他有用的例子源之間:
更新:谷歌刪除從Play商店應用據稱智力財產違規(雖然它只包含演示和鏈接到開源項目),作者現在提供apk可直接從http://goo.gl/ihcgs 下載欲瞭解更多詳情,請參閱https://plus.google.com/108176685096570584154/posts。注意:我不屬於作者。
感謝您的UI模式應用程序鏈接。 – howettl 2012-05-01 21:30:46
但是這會失去使用listView的全部觀點,因爲組中的所有項目(您展開的)都必須位於其中。如果你有很多項目,你也需要在那裏創建很多視圖... – 2013-12-31 15:31:47
@android developer:你可能會更好使用ScrollView,使用視圖填充它並將動畫應用到它們上需要。 ListView是一個爲大型列表優化的複雜組件;如果您只有多達12個項目,那麼滾動視圖可能更容易生成動畫 - 根據需要製作自己的塊組件併爲其中的視圖製作動畫。與ListView相比,主要的缺點是android不會創建/銷燬您的項目,因爲它們滾動進出視圖區域,並且容器不會被重用,但是如果您有幾件物品,這不是什麼大問題。 – ccpizza 2014-01-01 22:46:51
我爲一個簡單的列表視圖做了類似的工作。爲此,我重寫了getView方法並在每個列表項上應用了向上(或向下)的動畫翻譯。翻譯的程度取決於列表的位置項目。
https://github.com/idunnololz/AnimatedExpandableListView/ – 2015-06-29 11:00:59
我發現了一個可能的(部分)解決此問題的解決方法。
首先你需要存儲的ExpnadableListView的滾動狀態:
@Override
public void onScrollStateChanged(final AbsListView view, final int scrollState) {
this.mScrollState = scrollState;
}
public int getScrollState() {
return this.mScrollState;
}
爲ListView本身,你需要存儲被點擊了哪個組,以便只有它的孩子會得到動畫:
mListView.setOnGroupClickListener(...
@Override
public boolean onGroupClick(...){
mGroupPosition=groupPosition;
現在,在getChildView()方法,你檢查的滾動的狀態,如果是閒置時,啓動動畫,例如:
public View getChildView(...) {
// <=prepare rootView and return it later
if (groupPosition==mGroupPosition&&getScrollState() == OnScrollListener.SCROLL_STATE_IDLE)
rootView.setAnimation(...)
這將在您每次展開組時爲子視圖設置一個動畫。
的這個缺點是:只爲擴大孩子的意見
- 。您需要考慮額外的邏輯來在摺疊組時對其進行動畫處理。
- 所有動畫立即開始。如果您希望它可以起作用,您將需要一個接一個地添加多個動畫。
- 1. Fly In Animation for GridView
- 2. SimpleCursorTreeAdapter for ExpandableListView
- 3. ExpandableListView Mono for Android,ClickEvents
- 4. CustomAdapter for ExpandableListView使用CompoundDrawable
- 5. Android ExpandableListView onClickListener for Group行
- 6. ApplicationBar Animation
- 7. JQuery Animation
- 8. Uipagecontrol animation
- 9. SurfaceView Animation
- 10. jQuery Animation
- 11. ExpandableListView
- 12. Java Swing Animation without Thread.sleep
- 13. Animation in viewDidAppear
- 14. deleteRowsAtIndexPaths without animation
- 15. android resize animation
- 16. Raphael Sequential Animation
- 17. Word by word animation
- 18. Angular Disable Animation
- 19. TextBox TranslateTransform Animation
- 20. Angular Animation Directive
- 21. AS3 tweener animation jerking
- 22. Arc Animation Loading
- 23. Animation SVG or Canvas?
- 24. XNA spritesheet animation
- 25. Seamless SVG Animation
- 26. CABasic Animation Rotation
- 27. PAGECURL ANIMATION SUBTYPE
- 28. Core Animation和drawRect:
- 29. Irrlicht Human Mesh Animation
- 30. WPF Choppy/Jerky Animation
我不認爲有可能使行之間的間隙設置爲動畫,但我將幻燈片左/右動畫放在作爲孩子顯示的視圖上。這隻有真正的作用,因爲只有一個孩子。 – skorulis 2011-03-04 05:59:46