下面列出了android.view.animation.AnimationSet#getDuration() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Hides every view in a RecyclerView to simulate clearing the RecyclerView
* returns how long the animation takes to complete.
* Returns -1 if there is nothing to animate
*/
public static int animateFakeClearing(int lastVisibleItemPosition, int firstVisibleItemPosition, AutoSpanRecyclerView aRecyclerView, Animation.AnimationListener animationListener, boolean includeTranslation) {
final int DELAY_BETWEEN = 50;
int clearingDuration = 0;
int startPositionCol = getColumnPosFromIndex(firstVisibleItemPosition, aRecyclerView);
int startPositionRow = getRowPosFromIndex(firstVisibleItemPosition, aRecyclerView);
for (int i = lastVisibleItemPosition; i >= firstVisibleItemPosition; i--) {
final View VIEW = aRecyclerView.getChildAt(lastVisibleItemPosition - i);
int positionColumnDistance = Math.abs(getColumnPosFromIndex(i, aRecyclerView) - startPositionCol);
int positionRowDistance = Math.abs(getRowPosFromIndex(i, aRecyclerView) - startPositionRow);
int delay = (positionColumnDistance + positionRowDistance) * DELAY_BETWEEN + 1;
AnimationSet mHideAnimations = AnimationService.startAlphaHideAnimation(delay, VIEW, includeTranslation);
if (mHideAnimations == null) {
return -1;
}
int hideAnimationDuration = (int) mHideAnimations.getDuration();
if (hideAnimationDuration + delay > clearingDuration) {
clearingDuration = hideAnimationDuration + delay;
}
// If the view is the last to animate, then start the intent when the animation finishes.
if (i == lastVisibleItemPosition && animationListener != null) {
mHideAnimations.setAnimationListener(animationListener);
}
}
return clearingDuration;
}
/**
* Hides every view in a RecyclerView to simulate clearing the RecyclerView
* returns how long the animation takes to complete.
* Returns -1 if there is nothing to animate
*/
public static int animateFakeClearing(int lastVisibleItemPosition, int firstVisibleItemPosition, AutoSpanRecyclerView aRecyclerView, Animation.AnimationListener animationListener, boolean includeTranslation) {
final int DELAY_BETWEEN = 50;
int clearingDuration = 0;
int startPositionCol = getColumnPosFromIndex(firstVisibleItemPosition, aRecyclerView);
int startPositionRow = getRowPosFromIndex(firstVisibleItemPosition, aRecyclerView);
for(int i = lastVisibleItemPosition; i >= firstVisibleItemPosition; i--) {
final View VIEW = aRecyclerView.getChildAt(lastVisibleItemPosition - i);
int positionColumnDistance = Math.abs(getColumnPosFromIndex(i, aRecyclerView) - startPositionCol);
int positionRowDistance = Math.abs(getRowPosFromIndex(i, aRecyclerView) - startPositionRow);
int delay = (positionColumnDistance + positionRowDistance) * DELAY_BETWEEN + 1;
AnimationSet mHideAnimations = AnimationService.startAlphaHideAnimation(delay, VIEW, includeTranslation);
if (mHideAnimations == null) {
return -1;
}
int hideAnimationDuration = (int) mHideAnimations.getDuration();
if (hideAnimationDuration + delay > clearingDuration) {
clearingDuration = hideAnimationDuration + delay;
}
// If the view is the last to animate, then start the intent when the animation finishes.
if(i == lastVisibleItemPosition && animationListener != null) {
mHideAnimations.setAnimationListener(animationListener);
}
}
return clearingDuration;
}