maz*_*ork 7 android android-layout
该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
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1431 次 |
最近记录: |