gpt4 book ai didi

java - ExpandableListview 上的 LayoutTransition 动画无法正常工作

转载 作者:行者123 更新时间:2023-11-30 11:19:20 24 4
gpt4 key购买 nike

当一组在 ExpandableListView 上展开/折叠时,我想应用一个简单的 rotationX 动画。下面的代码在前两次展开时有效,但在两次/三次/五次之后不播放定义的动画。奇怪的是,我第一次展开/折叠时效果很好!

ExpandableListview exp = new ExpandableListview(context);
// set adapter code
LayoutTransition transition = new LayoutTransition();

Animator appearAnim = ObjectAnimator.ofFloat(null, "rotationX", 90f,0f).setDuration(transition.getDuration(LayoutTransition.APPEARING));
transition.setAnimator(LayoutTransition.APPEARING, appearAnim); // I also tried first argument equals DISSAPEARING, CHANGING, etc


exp.setLayoutTransition(transition);

有什么想法吗?这种做法是完全错误的吗???

此时我必须注意,这不是重复的!我正在寻找将使用 LayoutTransition 类/方法来解决的解决方案。

最佳答案

这里有一些很棒的示例,可以帮助您在 ExpandableListView 的展开/折叠时制作动画,在 android-flip 中使用 OpenGL 渲染动画的库,如果应用程序支持的最低 Android 版本是 4.0,我们可以使用标准的 Android SDK 方法而不是 OpenGL:View.setRotationX()、View.setScaleX() 等。启用硬件加速时(如果您的目标 API 级别 >=14,则默认启用),这些方法使用设备 GPU 非常有效。

你可以使用这个 FoldableLayout 为 ExpandableListView 的展开/折叠实现折叠动画。

enter image description here

Layout implementation in FoldableLayout:

The first element to design was a layout that can fold in half. Our approach was rather bold: the main layout (FoldableItemLayout) simply contains a specialized layout (BaseLayout). During the animation, the BaseLayout writes its contents to cache which is a specially created Bitmap object based on the size of the original layout. view plaincopy to clipboardprint?

class FoldableItemLayout extends FrameLayout {  
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
Bitmap cacheBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
mBaseLayout.setCacheCanvas(new Canvas(cacheBitmap));
}
}

class BaseLayout extends FrameLayout {
private Canvas mCacheCanvas;

private void setCacheCanvas(Canvas cacheCanvas) {
mCacheCanvas = cacheCanvas;
}

@Override
public void draw(Canvas canvas) {
mCacheCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
super.draw(mCacheCanvas);
}
}

In addition, we needed to use two extra Views (PartView) – for the upper and lower image halves – which would display the corresponding data in cache that represents the upper and lower halves of the image (Bitmap). Both Views encompass the entire area of the main layout, but display only the required parts. To achieve this effect, we calculated the Bitmap limits – and in the onDraw() method we made Canvas draw the required part via the drawBitmap (Bitmap bitmap, Rect src, RectF dst, Paint paint) method.

Then we managed to rotate these extra Views by setting the setRotationX() method to the corresponding angle, achieving independent rotation of the lower and upper parts of the images. To pull this off, we add a new parameter for the FoldableItemLayout – with the name FoldRotation.

来源:How to Make a Paper Folding Animation in Android?

关于java - ExpandableListview 上的 LayoutTransition 动画无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23294051/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com