问题描述
我有可以动态添加或删除的网格布局的GridView控件。
I have a GridView of layouts which can be dynamically added or removed to the grid.
在的iOS,为的GridView项目的本地行为是在网格的其他物品滑动到已删除的项目,或者滑动的地方,以腾出空间,当一个新项目被添加
In iOS, the native behavior for GridView items is for the other items in the grid to slide into the place of the removed item, or slide to make room when a new item is added.
不过在Android上的行为只是为了使更改立即弹出在屏幕上。我尝试添加自定义动画每个getView()调用使用GridView的适配器一些技巧,但是最终导致这里出现了一些问题:
However on Android the behavior is just for the changes to instantly pop in on the screen. I tried adding custom animations to each getView() call using some tricks in the GridView's adapter, but that ended up causing some problems seen here:
Android GridView控件在加载数据的时候设置更改
我试图具有各个视图控制动画代替适配器的getView()方法,但最终的结果是相同的。
I tried having the individual views control the animation instead of the getView() method of the adapter, but the end result was identical.
我也尝试过使用一个GridLayoutAnimationController,像这样的:
I also tried using a GridLayoutAnimationController, like this:
Animation animation = AnimationUtils.loadAnimation(mActivity, R.anim.grid_item_fadein);
GridLayoutAnimationController controller = new GridLayoutAnimationController(animation, .2f, .2f);
mGrid.setLayoutAnimation(controller);
这适用于所有的GridView内容的初始加载,但是任何对这些内容只是瞬间弹出像它在默认情况下。
This works on the initial load of all GridView content, but any changes to that content just instantly pop in like it does by default.
我觉得这是一个pretty的简单的功能,并且应该有一个更简单的方法来做到这一点。我从网上搜索看到的最好的是库这动画的交换,在电网的地方GridView的项目,但不是我正在寻找(在同一库中,当您从电网通过删除删除项目的同一时刻大意是我试图避免出现这种情况)。
I feel like this is a pretty simple feature, and there should be an easier way to do it. The best I've seen from searching online is a library which animates GridView items that swap places in the grid, but that isn't what I'm looking for (in that same library, when you remove an item from the Grid via deletion the same instant effect that I'm trying to avoid occurs).
,所以我还看到一个常见的答案是看APIDemos,有吨的例子。但据我所看到的,实际上有没有例子的动画GridView的内容的修改。
A common answer on SO I've also seen is "Look at the APIDemos, there are tons of examples." But as far as I can see, there are actually no examples for animating GridView content changes.
任何帮助是AP preciated,谢谢。
Any help is appreciated, thanks.
推荐答案
切特·哈泽想出了一个不错的视频就如何妥善处理的ListView动画。的基本概念可应用于GridView的。你可以在这里找到视频。
Chet Haase came out with a nice video on how to handle ListView animations properly. The basic concept can be applied to GridViews. You can find the video here.
如果您正在开发的API 1.0+,您将无法使用该视频中提到的引用动画功能(如ViewPropertyAnimator)除非你使用 NineOldAndroids 。
If you're developing for API 1.0+, you won't be able to use the referenced animation features that the video mentions (such as ViewPropertyAnimator) unless you use NineOldAndroids.
这篇关于安卓:动画修改GridView的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!