gpt4 book ai didi

android - Android的requestLayout()适合布局动画吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:16:38 27 4
gpt4 key购买 nike

requestLayout() 方法是在 Android 中创建动 Canvas 局的正确工具吗?

我们在 Adob​​e/Apache Flex 工作了几年,知道 invalidateProperties()commitProperties() 这两种方法。 Android 的 requestLayout()layout() 似乎有类似的用途。但是 docs提到有开销。

public class Paginator extends ViewGroup {
private float animatedCurrentPage = 1;
private final ObjectAnimator objectAnimator;

public Paginator(Context context, AttributeSet attrs) {
super(context, attrs);
objectAnimator = ObjectAnimator.ofFloat(this, "animatedCurrentPage", 0f);
}

public void jumpToPage(int page) {
objectAnimator.cancel();
objectAnimator.setFloatValues(animatedCurrentPage, page);
objectAnimator.start();
}

public void setAnimatedCurrentPage(float animatedCurrentPage) {
this.animatedCurrentPage = animatedCurrentPage;
requestLayout(); // <== queue an update of the layout
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// measure children here
}

@Override
protected void onLayout(boolean changed, final int l, final int t, final int r, final int b) {
// layout children here
}
}

最佳答案

我认为“invalidate()”应该改为调用 link

Drawing is handled by walking the tree and rendering each view that intersects the invalid region. Because the tree is traversed in-order, this means that parents will draw before (i.e., behind) their children, with siblings drawn in the order they appear in the tree. If you set a background drawable for a View, then the View will draw it for you before calling back to its onDraw() method.

Note that the framework will not draw views that are not in the invalid region.

To force a view to draw, call invalidate().

关于android - Android的requestLayout()适合布局动画吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16988644/

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