Android 是安卓';s requestLayout()是否适合布局动画?
Android 是安卓';s requestLayout()是否适合布局动画?,android,android-layout,Android,Android Layout,requestLayout()方法是在Android中创建动画布局的正确工具吗 我们与Adobe/Apache Flex合作了几年,了解了两种方法invalidateProperties()和commitProperties()。Android的requestLayout()和layout()似乎也有类似的用途。但提到这一点有点过头了 public class Paginator extends ViewGroup { private float animatedCurrentPage
requestLayout()
方法是在Android中创建动画布局的正确工具吗
我们与Adobe/Apache Flex合作了几年,了解了两种方法invalidateProperties()
和commitProperties()
。Android的requestLayout()
和layout()
似乎也有类似的用途。但提到这一点有点过头了
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
}
}
public类分页器扩展了ViewGroup{
私有float animatedCurrentPage=1;
私有最终ObjectAnimator ObjectAnimator;
公共分页器(上下文、属性集属性){
超级(上下文,attrs);
objectAnimator=objectAnimator.offload(这是“animatedCurrentPage”,0f);
}
公共空白跳转页(整版){
objectAnimator.cancel();
setFloatValues(animatedCurrentPage,第页);
objectAnimator.start();
}
public void setAnimatedCurrentPage(浮动animatedCurrentPage){
this.animatedCurrentPage=animatedCurrentPage;
requestLayout();//我认为“invalidate()”应该改为调用
通过遍历树并渲染每个视图来处理图形
与无效区域相交。因为树是按顺序遍历的,
这意味着父母将在孩子的前面(即后面)画画
孩子,兄弟姐妹按其在树中出现的顺序绘制。如果
为视图设置可绘制的背景,然后视图将绘制它
在调用其onDraw()方法之前
请注意,框架不会绘制不在无效区域中的视图
要强制绘制视图,请调用invalidate()
你有没有考虑过,而不是自己滚?