Search in sources :

Example 71 with TranslateAnimation

use of android.view.animation.TranslateAnimation in project BookReader by JustWayward.

the class EasyRecyclerView method showTipView.

public void showTipView(String tip) {
    tipView.setText(tip);
    Animation mShowAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
    mShowAction.setDuration(500);
    tipView.startAnimation(mShowAction);
    tipView.setVisibility(View.VISIBLE);
}
Also used : TranslateAnimation(android.view.animation.TranslateAnimation) Animation(android.view.animation.Animation) TranslateAnimation(android.view.animation.TranslateAnimation)

Example 72 with TranslateAnimation

use of android.view.animation.TranslateAnimation in project BookReader by JustWayward.

the class EasyRecyclerView method showTipViewAndDelayClose.

public void showTipViewAndDelayClose(String tip) {
    tipView.setText(tip);
    Animation mShowAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
    mShowAction.setDuration(500);
    tipView.startAnimation(mShowAction);
    tipView.setVisibility(View.VISIBLE);
    tipView.postDelayed(new Runnable() {

        @Override
        public void run() {
            Animation mHiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f);
            mHiddenAction.setDuration(500);
            tipView.startAnimation(mHiddenAction);
            tipView.setVisibility(View.GONE);
        }
    }, 2200);
}
Also used : TranslateAnimation(android.view.animation.TranslateAnimation) Animation(android.view.animation.Animation) TranslateAnimation(android.view.animation.TranslateAnimation)

Example 73 with TranslateAnimation

use of android.view.animation.TranslateAnimation in project BookReader by JustWayward.

the class ReboundScrollView method dispatchTouchEvent.

/**
 * 在触摸事件中, 处理上拉和下拉的逻辑
 */
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (contentView == null) {
        return super.dispatchTouchEvent(ev);
    }
    int action = ev.getAction();
    switch(action) {
        case MotionEvent.ACTION_DOWN:
            // 判断是否可以上拉和下拉
            canPullDown = isCanPullDown();
            canPullUp = isCanPullUp();
            // 记录按下时的Y值
            startY = ev.getY();
            break;
        case MotionEvent.ACTION_UP:
            if (!isMoved)
                // 如果没有移动布局, 则跳过执行
                break;
            // 开启动画
            TranslateAnimation anim = new TranslateAnimation(0, 0, contentView.getTop(), originalRect.top);
            anim.setDuration(ANIM_TIME);
            contentView.startAnimation(anim);
            // 设置回到正常的布局位置
            contentView.layout(originalRect.left, originalRect.top, originalRect.right, originalRect.bottom);
            // 将标志位设回false
            canPullDown = false;
            canPullUp = false;
            isMoved = false;
            break;
        case MotionEvent.ACTION_MOVE:
            // 在移动的过程中, 既没有滚动到可以上拉的程度, 也没有滚动到可以下拉的程度
            if (!canPullDown && !canPullUp) {
                startY = ev.getY();
                canPullDown = isCanPullDown();
                canPullUp = isCanPullUp();
                break;
            }
            // 计算手指移动的距离
            float nowY = ev.getY();
            int deltaY = (int) (nowY - startY);
            // 是否应该移动布局
            boolean shouldMove = // 可以下拉, 并且手指向下移动
            (canPullDown && deltaY > 0) || // 可以上拉, 并且手指向上移动
            (canPullUp && deltaY < 0) || // 既可以上拉也可以下拉(这种情况出现在ScrollView包裹的控件比ScrollView还小)
            (canPullUp && canPullDown);
            if (shouldMove) {
                // 计算偏移量
                int offset = (int) (deltaY * MOVE_FACTOR);
                // 随着手指的移动而移动布局
                contentView.layout(originalRect.left, originalRect.top + offset, originalRect.right, originalRect.bottom + offset);
                // 记录移动了布局
                isMoved = true;
            }
            break;
        default:
            break;
    }
    return super.dispatchTouchEvent(ev);
}
Also used : TranslateAnimation(android.view.animation.TranslateAnimation)

Example 74 with TranslateAnimation

use of android.view.animation.TranslateAnimation in project BookReader by JustWayward.

the class SubjectBookListActivity method showTagGroup.

private void showTagGroup() {
    if (mTagList.isEmpty()) {
        ToastUtils.showToast(getString(R.string.network_error_tips));
        return;
    }
    Animation mShowAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
    mShowAction.setDuration(400);
    rsvTags.startAnimation(mShowAction);
    rsvTags.setVisibility(View.VISIBLE);
}
Also used : TranslateAnimation(android.view.animation.TranslateAnimation) Animation(android.view.animation.Animation) TranslateAnimation(android.view.animation.TranslateAnimation)

Example 75 with TranslateAnimation

use of android.view.animation.TranslateAnimation in project commons-gdx by gemserk.

the class AdViewHandler method hideAds.

private void hideAds(Message msg) {
    AdsParameters adsParameters = (AdsParameters) msg.obj;
    if (adView.getVisibility() == View.GONE)
        return;
    if (adsParameters != null) {
        if (adsParameters.animationsEnabled) {
            ArrayList<AdsAnimation> animations = adsParameters.animations;
            int size = animations.size();
            for (int i = 0; i < size; i++) {
                AdsAnimation adsAnimation = animations.get(i);
                if (adsAnimation.type == AdsAnimation.Type.Alpha) {
                    AlphaAnimation animation = new AlphaAnimation(1.0f, 0.0f);
                    animation.setDuration(adsAnimation.duration);
                    animation.setFillAfter(false);
                    animation.setInterpolator(new LinearInterpolator());
                    animation.setAnimationListener(new HideAnimationListener(adView));
                    // 
                    adView.startAnimation(animation);
                // System.out.println("hiding with animation alpha");
                } else if (adsAnimation.type == Type.Translation) {
                    float yDelta = verticalAlign == RelativeLayout.ALIGN_PARENT_TOP ? -75f : 75f;
                    TranslateAnimation animation = new TranslateAnimation(0, 0, 0, yDelta);
                    animation.setDuration(adsAnimation.duration);
                    animation.setFillAfter(false);
                    animation.setInterpolator(new LinearInterpolator());
                    animation.setAnimationListener(new HideAnimationListener(adView));
                    adView.startAnimation(animation);
                // System.out.println("hiding with animation translation");
                } else {
                    adView.setVisibility(View.GONE);
                }
            }
        } else {
            adView.setVisibility(View.GONE);
        }
    } else {
        adView.setVisibility(View.GONE);
    }
}
Also used : LinearInterpolator(android.view.animation.LinearInterpolator) TranslateAnimation(android.view.animation.TranslateAnimation) AlphaAnimation(android.view.animation.AlphaAnimation)

Aggregations

TranslateAnimation (android.view.animation.TranslateAnimation)229 Animation (android.view.animation.Animation)109 AlphaAnimation (android.view.animation.AlphaAnimation)90 AnimationSet (android.view.animation.AnimationSet)69 ScaleAnimation (android.view.animation.ScaleAnimation)44 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)30 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)27 View (android.view.View)22 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)22 TextView (android.widget.TextView)18 AnimationListener (android.view.animation.Animation.AnimationListener)17 LinearInterpolator (android.view.animation.LinearInterpolator)13 RotateAnimation (android.view.animation.RotateAnimation)13 ClipRectAnimation (android.view.animation.ClipRectAnimation)12 ListView (android.widget.ListView)12 CurvedTranslateAnimation (com.android.server.wm.animation.CurvedTranslateAnimation)12 ImageView (android.widget.ImageView)11 LayoutAnimationController (android.view.animation.LayoutAnimationController)8 WindowAnimation_activityCloseEnterAnimation (com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation)8 WindowAnimation_activityCloseExitAnimation (com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation)8