下面列出了android.view.View#clearAnimation ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Shows only the specified child. The other displays Views exit the screen,
* optionally with the with the {@link #getOutAnimation() out animation} and
* the specified child enters the screen, optionally with the
* {@link #getInAnimation() in animation}.
*
* @param childIndex The index of the child to be shown.
* @param animate Whether or not to use the in and out animations, defaults
* to true.
*/
void showOnly(int childIndex, boolean animate) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (i == childIndex) {
if (animate && mInAnimation != null) {
child.startAnimation(mInAnimation);
}
child.setVisibility(View.VISIBLE);
mFirstTime = false;
} else {
if (animate && mOutAnimation != null && child.getVisibility() == View.VISIBLE) {
child.startAnimation(mOutAnimation);
} else if (child.getAnimation() == mInAnimation)
child.clearAnimation();
child.setVisibility(View.GONE);
}
}
}
private void stopAnimation() {
mHandler.removeCallbacks(rainProc);
mHandler.removeCallbacks(snowProc);
mHandler.removeCallbacks(cloudProc);
mHandler.removeCallbacks(lightningProc);
mHandler.removeCallbacks(sunshaineProc);
for (int i = 0; i != rlBackgroundView.getChildCount(); ++i) {
View view = rlBackgroundView.getChildAt(i);
if (view != null) {
view.clearAnimation();
}
}
rlBackgroundView.removeAllViews();
mSpecialWeatherNumRain = 0;
mSpecialWeatherNumCloud = 0;
mSpecialWeatherNumSnow = 0;
mSpecialWeatherNumLightning = 0;
}
private void animateDragged() {
if (mLastDragged >= 0) {
final View v = getChildAt(mLastDragged);
final Rect r = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
r.inset(-r.width() / 20, -r.height() / 20);
v.measure(MeasureSpec.makeMeasureSpec(r.width(), MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(r.height(), MeasureSpec.EXACTLY));
v.layout(r.left, r.top, r.right, r.bottom);
AnimationSet animSet = new AnimationSet(true);
ScaleAnimation scale = new ScaleAnimation(0.9091f, 1, 0.9091f, 1, v.getWidth() / 2, v.getHeight() / 2);
scale.setDuration(ANIMATION_DURATION);
AlphaAnimation alpha = new AlphaAnimation(1, .5f);
alpha.setDuration(ANIMATION_DURATION);
animSet.addAnimation(scale);
animSet.addAnimation(alpha);
animSet.setFillEnabled(true);
animSet.setFillAfter(true);
v.clearAnimation();
v.startAnimation(animSet);
}
}
@Override
protected void removeDetachedView(View child, boolean animate) {
ViewHolder vh = getChildViewHolderInt(child);
if (vh != null) {
if (vh.isTmpDetached()) {
vh.clearTmpDetachFlag();
} else if (!vh.shouldIgnore()) {
throw new IllegalArgumentException("Called removeDetachedView with a view which"
+ " is not flagged as tmp detached." + vh + exceptionLabel());
}
}
// Clear any android.view.animation.Animation that may prevent the item from
// detaching when being removed. If a child is re-added before the
// lazy detach occurs, it will receive invalid attach/detach sequencing.
child.clearAnimation();
dispatchChildDetached(child);
super.removeDetachedView(child, animate);
}
public static void animateIn(final @NonNull View view, final @NonNull Animation animation) {
if (view.getVisibility() == View.VISIBLE) return;
view.clearAnimation();
animation.reset();
animation.setStartTime(0);
view.setVisibility(View.VISIBLE);
view.startAnimation(animation);
}
public static void wave(final View layer, float scale, int duration, float stepOffset) {
final ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, scale, 1.0f, scale, Animation.RELATIVE_TO_SELF, (float) 0.5, Animation.RELATIVE_TO_SELF, (float) 0.5);
scaleAnimation.setDuration(duration);
scaleAnimation.setInterpolator(new OffsetCycleInterpolator(stepOffset));
scaleAnimation.setRepeatCount(Animation.INFINITE);
layer.clearAnimation();
layer.startAnimation(scaleAnimation);
}
@Override
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, final ViewGroup parent) {
View view = null;
ItemBase dt = data.get(groupPosition).get(childPosition);
if (dt.isMarkedToDelete()) {
view = getItemMarkedView(groupPosition, childPosition, convertView, parent);
}
else {
view = getItemWithMenuView(groupPosition, childPosition, convertView, parent);
}
view.clearAnimation();
return view;
}
public void slidingByDelta(View view ,float delta){
if(view == null){
return;
}
view.clearAnimation();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
view.setTranslationY(delta);
}else{
// ViewHelper.setTranslationY(view, delta);
}
}
@UiThread public static void startBeatsAnimation(@NonNull View view) {
view.clearAnimation();
if (view.getAnimation() != null) {
view.getAnimation().cancel();
}
List<ObjectAnimator> animators = getBeats(view);
for (ObjectAnimator anim : animators) {
anim.setDuration(300).start();
anim.setInterpolator(interpolator);
}
}
public void smoothTo(View view ,float y, long duration){
if(view == null){
return;
}
view.clearAnimation();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
android.animation.ObjectAnimator.ofFloat(view, "translationY", y).setDuration(duration).start();
}else{
com.nineoldandroids.animation.ObjectAnimator.ofFloat(view, "translationY", y).setDuration(duration).start();
}
}
public void slidingByDelta(View view, float delta) {
if (view == null) {
return;
}
view.clearAnimation();
view.setTranslationY(delta);
}
public void slidingToY(View view, float y) {
if (view == null) {
return;
}
view.clearAnimation();
view.setY(y);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
ItemBase dt = data.get(position);
if (dt.isMarkedToDelete()) {
view = getItemMarkedView(position, convertView, parent);
}
else {
view = getItemWithMenuView(position, convertView, parent);
}
view.clearAnimation();
return view;
}
private void clearAnimation(View View) {
View.clearAnimation();
if (View.getAnimation() != null) {
View.getAnimation().cancel();
}
}
@Override
public void showOnlyNoAnimation(final int previousIndex, final int childIndex) {
for (int i = 0; i < parent.getChildCount(); i++) {
View child = parent.getChildAt(i);
child.setVisibility(i == childIndex ? View.VISIBLE : View.GONE);
if (child.getAnimation() == parent.mInAnimation) {
parent.mInAnimation.setAnimationListener(null);
child.clearAnimation();
} else if (child.getAnimation() == parent.mOutAnimation) {
child.clearAnimation();
}
}
}
@UiThread public static void startBeatsAnimation(@NonNull View view) {
view.clearAnimation();
if (view.getAnimation() != null) {
view.getAnimation().cancel();
}
List<ObjectAnimator> animators = getBeats(view);
for (ObjectAnimator anim : animators) {
anim.setDuration(300).start();
anim.setInterpolator(interpolator);
}
}
private void itemDidDisappear() {
final int itemCount = mRayLayout.getChildCount();
for (int i = 0; i < itemCount; i++) {
View item = mRayLayout.getChildAt(i);
item.clearAnimation();
}
mRayLayout.switchState(false);
}
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_UPDATE_LOADING:
if (isFirstRun()) {
progressDialog = ProgressDialog.show(
Main.this,
getString(R.string.app_name), getString(R.string.loading), false, false);
}
Animation rotation = AnimationUtils.loadAnimation(context, R.anim.refresh_rotate);
RelativeLayout layout = new RelativeLayout(context);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
ImageView imageView = new ImageView(context);
imageView.setLayoutParams(params);
layout.setGravity(Gravity.CENTER_VERTICAL | Gravity.TOP);
layout.addView(imageView);
imageView.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_refersh));
imageView.startAnimation(rotation);
if (mMenuRefersh != null) {
mMenuRefersh.setActionView(layout);
}
break;
case MESSAGE_UPDATE_COMPLETE:
try {
Fragment fragment = mScrollTabsFragment.getCurrentFragment();
if (fragment instanceof QuestionsListFragment) {
((QuestionsListFragment) fragment).updateQuestionsFromDatabase();
}
} catch (NullPointerException e) {
e.printStackTrace();
} finally {
mScrollTabsFragment.notifyDatasetChanged();
}
if (mMenuRefersh != null) {
View v = mMenuRefersh.getActionView();
if (v != null) {
v.clearAnimation();
}
mMenuRefersh.setActionView(null);
}
if (progressDialog != null) {
progressDialog.dismiss();
}
if (mFetchQuestionsTask.hasError()) {
Helper.showShortToast(context, mFetchQuestionsTask.getErrorMessage());
}
break;
case MESSAGE_UPDATE_SHOW_RESULT:
if (mFetchQuestionsTask != null) {
String message = getString(R.string.no_newer_questions);
if (mFetchQuestionsTask.getAffectedRows() > 0) {
message = String.format(getString(R.string.affectRows), mFetchQuestionsTask.getAffectedRows());
}
Helper.showShortToast(context, message);
}
break;
}
}
protected void performDragAndDropSwapping(int from, int to) {
mPopulating = true;
Logs.d("drag----" + from + " " + to + " " + mAdapter.getCount());
if (from != to && isLastItemCouldDrag ? true : to != mAdapter.getCount() - 1) {
final View removedChild = getChildAt(from);
removedChild.clearAnimation();
removeViewInLayout(removedChild);
addViewInLayout(removedChild, to, removedChild.getLayoutParams());
}
mControlHeight = measureChildrens(false);
layoutChildrens(to, true);
mPopulating = false;
}
private void setGridVisibility(boolean visible, boolean animate)
{
if (gridVisible == visible)
{
return;
}
gridVisible = visible;
View parent = (View) getGridView().getParent();
if (visible)
{
if (animate)
{
loadingView.startAnimation(AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_out));
parent.startAnimation(AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in));
}
else
{
loadingView.clearAnimation();
parent.clearAnimation();
}
loadingView.setVisibility(View.GONE);
if (parent != null)
parent.setVisibility(View.VISIBLE);
}
else
{
if (animate)
{
loadingView.startAnimation(AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in));
parent.startAnimation(AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_out));
}
else
{
loadingView.clearAnimation();
parent.clearAnimation();
}
loadingView.setVisibility(View.VISIBLE);
if (parent != null)
parent.setVisibility(View.GONE);
}
}