Czy metoda requestLayout()
jest odpowiednim narzędziem do tworzenia animowanego układu w systemie Android?Czy Android requestLayout() jest odpowiedni do animacji układu?
Pracowaliśmy kilka lat z Adobe/Apache Flex i znamy dwie metody: invalidateProperties()
i commitProperties()
. Wygląda na to, że Androidowi requestLayout()
i layout()
służy podobny cel. Ale docs wspomnieć, że istnieje narzut.
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
}
}
Czy bierzesz pod uwagę http://developer.android.com/reference/android/widget/ViewFlipper.html lub http://developer.android.com/reference/android/support/v4/view/ViewPager. html zamiast toczyć własne? – FunkTheMonk