Phương thức requestLayout()
có phải là công cụ thích hợp để tạo bố cục hoạt ảnh trong Android không?Yêu cầuLayout() của Android có dành cho hoạt ảnh bố cục không?
Chúng tôi đã làm việc một số năm với Adobe/Apache Flex và biết hai phương pháp invalidateProperties()
và commitProperties()
. Có vẻ như requestLayout()
và layout()
của Android phục vụ một mục đích tương tự. Nhưng docs đề cập đến có một chi phí.
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
}
}
Bạn đã xem http://developer.android.com/reference/android/widget/ViewFlipper.html hoặc http://developer.android.com/reference/android/support/v4/view/ViewPager. html chứ không phải là của riêng bạn? – FunkTheMonk