/** * 用于启动照相机扫描二维码,在activity的onCreate里面构造出来 * 在activity的生命周期中调用此类相对应的生命周期方法 * * @param activity 扫描的activity * @param scanPreview 预览的SurfaceView * @param scanContainer 扫描的布局,全屏布局 * @param scanCropView 扫描的矩形区域 * @param scanLine 扫描线 */ public ScanManager(Activity activity, SurfaceView scanPreview, View scanContainer, View scanCropView, ImageView scanLine, int scanMode, ScanListener listener) { this.activity = activity; this.scanPreview = scanPreview; this.scanContainer = scanContainer; this.scanCropView = scanCropView; this.scanLine = scanLine; this.listener = listener; this.scanMode = scanMode; //启动动画 TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.9f); animation.setDuration(4500); animation.setRepeatCount(-1); animation.setRepeatMode(Animation.RESTART); scanLine.startAnimation(animation); }
/** * 用于启动照相机扫描二维码,在activity的onCreate里面构造出来 * 在activity的生命周期中调用此类相对应的生命周期方法 * @param activity 扫描的activity * @param scanPreview 预览的SurfaceView * @param scanContainer 扫描的布局,全屏布局 * @param scanCropView 扫描的矩形区域 * @param scanLine 扫描线 * * */ public ScanManager(Activity activity, SurfaceView scanPreview, View scanContainer, View scanCropView, ImageView scanLine, int scanMode, ScanListener listener) { this.activity=activity; this.scanPreview=scanPreview; this.scanContainer=scanContainer; this.scanCropView=scanCropView; this.scanLine=scanLine; this.listener=listener; this.scanMode=scanMode; //启动动画 TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.9f); animation.setDuration(4500); animation.setRepeatCount(-1); animation.setRepeatMode(Animation.RESTART); scanLine.startAnimation(animation); }
@Override public Animation createOptionDisappearAnimation(OptionButton optionButton, int index) { AnimationSet animationSet = new AnimationSet(true); TranslateAnimation translateAnimation= new TranslateAnimation( 0 ,getYMenuButton().getX() - optionButton.getX() ,0 ,getYMenuButton().getY() - optionButton.getY() ); translateAnimation.setDuration(getOptionSD_AnimationDuration()); AlphaAnimation alphaAnimation = new AlphaAnimation(1,0); alphaAnimation.setDuration(getOptionSD_AnimationDuration()); animationSet.addAnimation(translateAnimation); animationSet.addAnimation(alphaAnimation); //为不同的Option设置延时 if (index % 2 == 0) { animationSet.setStartOffset(getOptionSD_AnimationDuration()/2); } return animationSet; }
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); }
/** * Translates the adapter in Y * * @param of offset in px */ public void translateHeader(float of) { float ofCalculated = of * mScrollMultiplier; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && of < mHeader.getHeight()) { mHeader.setTranslationY(ofCalculated); } else if (of < mHeader.getHeight()) { TranslateAnimation anim = new TranslateAnimation(0, 0, ofCalculated, ofCalculated); anim.setFillAfter(true); anim.setDuration(0); mHeader.startAnimation(anim); } mHeader.setClipY(Math.round(ofCalculated)); if (mParallaxScroll != null) { final RecyclerView.ViewHolder holder = mRecyclerView.findViewHolderForAdapterPosition(0); float left; if (holder != null) { left = Math.min(1, ((ofCalculated) / (mHeader.getHeight() * mScrollMultiplier))); }else { left = 1; } mParallaxScroll.onParallaxScroll(left, of, mHeader); } }
private void initAnimation() { paint.setStrokeWidth(getHeight() * 0.01f); paint.setAntiAlias(true); paint.setDither(true); paint.setColor(Color.argb(248, 255, 255, 255)); paint.setStrokeWidth(20f); paint.setStyle(Paint.Style.STROKE); paint.setStrokeJoin(Paint.Join.ROUND); paint.setStrokeCap(Paint.Cap.ROUND); paintGlow.set(paint); paintGlow.setColor(Color.argb(235, 74, 138, 255)); paintGlow.setStrokeWidth(30f); paintGlow.setMaskFilter(new BlurMaskFilter(15, BlurMaskFilter.Blur.NORMAL)); float deltaY = (CameraOverlayView.PADDING * 2) * getHeight(); Log.i(TAG, String.format("Delta Y : %s", deltaY)); TranslateAnimation mAnimation = new TranslateAnimation(0f, 0f, 0f, deltaY); mAnimation.setDuration(3000); mAnimation.setRepeatCount(-1); mAnimation.setRepeatMode(Animation.REVERSE); mAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); setAnimation(mAnimation); }
/** * 结束时的动画 平移到底部 */ public static Animation translateAlphaFinishAnimation() { TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1f); AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); setDefaultConfig(translateAnimation, true); setDefaultConfig(alphaAnimation, true); translateAnimation.setDuration(DEFAULT_DIALOG_FINISH_ANIM_TIME); alphaAnimation.setDuration(DEFAULT_DIALOG_FINISH_ANIM_TIME); AnimationSet animationSet = new AnimationSet(false); animationSet.addAnimation(alphaAnimation); animationSet.addAnimation(translateAnimation); return animationSet; }
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(R.layout.activity_scan); scanPreview = (SurfaceView) findViewById(R.id.capture_preview); scanContainer = (RelativeLayout) findViewById(R.id.capture_container); scanCropView = (RelativeLayout) findViewById(R.id.capture_crop_view); scanLine = (ImageView) findViewById(R.id.capture_scan_line); inactivityTimer = new InactivityTimer(this); beepManager = new BeepManager(this); TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.9f); animation.setDuration(4500); animation.setRepeatCount(-1); animation.setRepeatMode(Animation.RESTART); scanLine.startAnimation(animation); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); }
private void startAnim(View widget) { int distance = widget.getHeight(); widget.setVisibility(0); this.mFloatLayout.setVisibility(0); AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f); alphaAnimation.setDuration(200); alphaAnimation.setStartOffset(200); this.mFloatLayout.setAnimation(alphaAnimation); this.mAnimation = new TranslateAnimation(0.0f, 0.0f, (float) distance, 0.0f); this.mAnimation.setDuration(200); this.mAnimation.setStartOffset(200); widget.setAnimation(this.mAnimation); this.mAnimation.start(); alphaAnimation.start(); }
/** * 对话框的布局动画 */ @Override public Animation loadLayoutAnimation() { if (layoutAnim) { if (layoutAnimation == null) { TranslateAnimation translateAnimation = new TranslateAnimation( Animation.RELATIVE_TO_PARENT, 0f, Animation.RELATIVE_TO_PARENT, 0f, Animation.RELATIVE_TO_PARENT, 1f, Animation.RELATIVE_TO_PARENT, 0f); setDefaultConfig(translateAnimation, false); translateAnimation.setDuration(160); return translateAnimation; } else { return layoutAnimation; } } return null; }
public void display(float x) { this.startPositionX = x; this.lastPositionX = x; recordButtonFab.setVisibility(View.VISIBLE); float translation = ViewCompat.getLayoutDirection(recordButtonFab) == ViewCompat.LAYOUT_DIRECTION_LTR ? -.25f : .25f; AnimationSet animation = new AnimationSet(true); animation.addAnimation(new TranslateAnimation(Animation.RELATIVE_TO_SELF, translation, Animation.RELATIVE_TO_SELF, translation, Animation.RELATIVE_TO_SELF, -.25f, Animation.RELATIVE_TO_SELF, -.25f)); animation.addAnimation(new ScaleAnimation(.5f, 1f, .5f, 1f, Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f)); animation.setFillBefore(true); animation.setFillAfter(true); animation.setDuration(ANIMATION_DURATION); animation.setInterpolator(new OvershootInterpolator()); recordButtonFab.startAnimation(animation); }
public void moveTo(float x) { this.lastPositionX = x; float offset = getOffset(x); int widthAdjustment = getWidthAdjustment(); Animation translateAnimation = new TranslateAnimation(Animation.ABSOLUTE, widthAdjustment + offset, Animation.ABSOLUTE, widthAdjustment + offset, Animation.RELATIVE_TO_SELF, -.25f, Animation.RELATIVE_TO_SELF, -.25f); translateAnimation.setDuration(0); translateAnimation.setFillAfter(true); translateAnimation.setFillBefore(true); recordButtonFab.startAnimation(translateAnimation); }
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(R.layout.activity_capture); scanPreview = (SurfaceView) findViewById(R.id.capture_preview); scanContainer = (RelativeLayout) findViewById(R.id.capture_container); scanCropView = (RelativeLayout) findViewById(R.id.capture_crop_view); scanLine = (ImageView) findViewById(R.id.capture_scan_line); inactivityTimer = new InactivityTimer(this); beepManager = new BeepManager(this); TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation .RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.9f); animation.setDuration(4500); animation.setRepeatCount(-1); animation.setRepeatMode(Animation.RESTART); scanLine.startAnimation(animation); }
private void adjustSizes(boolean isAnimated) { int width = getWidth(); if (width > 0 && this.items != null) { LayoutParams viewLayoutParams = (LayoutParams) this.currentView.getLayoutParams(); viewLayoutParams.width = width / this.items.length; this.currentView.setLayoutParams(viewLayoutParams); if (!this.inAnimation) { if (isAnimated) { this.inAnimation = true; TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, this.currentIndex - this.lastIndex, 0, 0, 0, 0); animation.setDuration(300); animation.setAnimationListener(this); this.currentView.startAnimation(animation); return; } viewLayoutParams.leftMargin = this.currentIndex * viewLayoutParams.width; this.currentView.setLayoutParams(viewLayoutParams); } } }
/** * 将内容布局移动到原位置 可以在UP事件中调用, 也可以在其他需要的地方调用, 如手指移动到当前ScrollView外时 */ private void boundBack() { if (!isMoved) { return; // 如果没有移动布局, 则跳过执行 } // 开启动画 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; }
/** * 位置还原 */ private void recoverLayout() { if (!isMoved) { return;//如果没有移动布局,则跳过执行 } for (int i = 0; i < mMoveViews.size(); i++) { if (mMoveRects.get(i) != null) { TranslateAnimation anims = new TranslateAnimation(0, 0, mMoveViews.get(i).getTop(), mMoveRects.get(i).top); anims.setDuration(ANIM_TIME); mMoveViews.get(i).startAnimation(anims); mMoveViews.get(i).layout(mMoveRects.get(i).left, mMoveRects.get(i).top, mMoveRects.get(i).right, mMoveRects.get(i).bottom); } } TranslateAnimation anim = new TranslateAnimation(0, 0, childView.getTop() - originalRect.top, 0); anim.setDuration(ANIM_TIME); childView.startAnimation(anim); childView.layout(originalRect.left, originalRect.top, originalRect.right, originalRect.bottom); isMoved = false; }
private boolean animatefigure(final Tuple<Integer, Integer> from, final Tuple<Integer, Integer> to, int speed) { if (figuren[from.first][from.last] != null) { Point rectFrom = chessboardView.getRectangleCoordinates(from); Point rectTo = chessboardView.getRectangleCoordinates(to); int deltaX = rectTo.x - rectFrom.x; int deltaY = rectTo.y - rectFrom.y; TranslateAnimation translateAnimation = new TranslateAnimation(0, deltaX, 0, deltaY); translateAnimation.setDuration(speed); translateAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); translateAnimation.setAnimationListener(new AnimationEndListener() { @Override public void onAnimationEnd(Animation animation) { update(); if (aiGame && !board.isWhitesTurn()) { aimove(); } else { stateAllowClick = true; } } }); figuren[from.first][from.last].startAnimation(translateAnimation); return true; } return false; }
/** * BottomSheet升起动画 */ private void animateUp() { if (mContentView == null) { return; } TranslateAnimation translate = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0f ); AlphaAnimation alpha = new AlphaAnimation(0, 1); AnimationSet set = new AnimationSet(true); set.addAnimation(translate); set.addAnimation(alpha); set.setInterpolator(new DecelerateInterpolator()); set.setDuration(mAnimationDuration); set.setFillAfter(true); mContentView.startAnimation(set); }
public static void setActivityToolbarReset(Toolbar aMainToolbar, Toolbar aDecorativeToolbar, Activity aActivity, float fromToolbarPosition, float fromMainToolbarPosition) { final int TOOLBAR_TRANSLATION_DURATION = 700; float DECORATIVE_TOOLBAR_HEIGHT = -1 * aActivity.getResources().getDimension(R.dimen.additional_toolbar_height); if(fromMainToolbarPosition == 0) { DECORATIVE_TOOLBAR_HEIGHT += aActivity.getResources().getDimension(R.dimen.main_toolbar_height); } else { Animation moveMainToolbarAnimation = new TranslateAnimation(0, 0, fromMainToolbarPosition, 0); moveMainToolbarAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); moveMainToolbarAnimation.setDuration(TOOLBAR_TRANSLATION_DURATION); aMainToolbar.startAnimation(moveMainToolbarAnimation); } float fromTranslationY = (fromToolbarPosition < DECORATIVE_TOOLBAR_HEIGHT) ? DECORATIVE_TOOLBAR_HEIGHT : fromToolbarPosition; Animation moveToolbarAnimation = new TranslateAnimation(0, 0, fromTranslationY, 0); moveToolbarAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); moveToolbarAnimation.setDuration(TOOLBAR_TRANSLATION_DURATION); aDecorativeToolbar.startAnimation(moveToolbarAnimation); }
private void slideInUp(View view, Animation.AnimationListener animationListener) { AlphaAnimation fadeIn = new AlphaAnimation(0.0f, 1.0f); TranslateAnimation transIn = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.0f); final AnimationSet animationSet = new AnimationSet(true); animationSet.addAnimation(fadeIn); animationSet.addAnimation(transIn); animationSet.setDuration(200); if (animationListener != null) { animationSet.setAnimationListener(animationListener); } view.setVisibility(View.VISIBLE); view.clearAnimation(); view.startAnimation(animationSet); }
@Override public boolean dispatchTouchEvent(MotionEvent event) { int act = event.getAction(); if ((act == MotionEvent.ACTION_UP || act == MotionEvent.ACTION_CANCEL) && outBound) { outBound = false; // scroll back } if (!lisGestureDetector.onTouchEvent(event)) { outBound = false; } else { outBound = true; } Rect rect = new Rect(); getLocalVisibleRect(rect); TranslateAnimation am = new TranslateAnimation( 0, 0, -rect.top, 0); am.setDuration(300); startAnimation(am); scrollTo(0, 0); return super.dispatchTouchEvent(event); }
/*** * 回缩动画 */ public void animation() { TranslateAnimation taa = new TranslateAnimation(0, 0, top + 200, initTop + 200); taa.setDuration(200); imageView.startAnimation(taa); imageView.layout(imageView.getLeft(), initTop, imageView.getRight(), initbottom); // 开启移动动画 TranslateAnimation ta = new TranslateAnimation(0, 0, inner.getTop(), normal.top); ta.setDuration(200); inner.startAnimation(ta); // 设置回到正常的布局位置 inner.layout(normal.left, normal.top, normal.right, normal.bottom); normal.setEmpty(); /** line **/ TranslateAnimation taaa = new TranslateAnimation(0, 0, line.getTop(), init_line_bottom); ta.setDuration(200); line.startAnimation(ta); line.layout(line.getLeft(), line.getTop(), line.getRight(), init_line_bottom); isCount = false; y = 0;// 手指松开要归0. /** 动画执行 **/ if (top > -150) turnListener.onTurn(); }
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); }
public void hideTipView(long delayMillis) { 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); } }, delayMillis); }
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); }
private void hideTagGroup() { 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(400); rsvTags.startAnimation(mHiddenAction); rsvTags.setVisibility(View.GONE); }
/** * 对话框启动时的动画 */ @Override public Animation loadStartAnimation() { TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0f); AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1); setDefaultConfig(translateAnimation, false); setDefaultConfig(alphaAnimation, false); AnimationSet animationSet = new AnimationSet(false); animationSet.addAnimation(alphaAnimation); animationSet.addAnimation(translateAnimation); return animationSet; }
private void showStreamPopWindowForView(View view) { this.animTopIn = new TranslateAnimation(1, 0.0f, 1, 0.0f, 1, -0.5f, 1, 0.0f); this.animTopIn.setDuration(300); this.layoutView.setAnimation(this.animTopIn); int[] arrayOfInf = new int[2]; view.getLocationInWindow(arrayOfInf); int x = arrayOfInf[0]; int y = arrayOfInf[1] + Util.dipToPx(45.0f); this.mPopupWindow.setAnimationStyle(R.style.popwin_anim_style); this.mPopupWindow.showAtLocation(view, 51, x, y); }
/** * 生成TranslateAnimation * * @param durationMillis 动画显示时间 * @param start 初始位置 */ public static Animation getTranslateAnimation(int start, int end, int durationMillis) { Animation translateAnimation = new TranslateAnimation(0, 0, start, end); translateAnimation.setDuration(durationMillis); translateAnimation.setFillEnabled(true); translateAnimation.setFillAfter(true); return translateAnimation; }
public static void hideLine(Context context,View top,View bottom) { Animation topTranslateAnimation=new TranslateAnimation(0, 0, 0, -DensityUtil.dip2px(context,56f)); topTranslateAnimation.setDuration(300); topTranslateAnimation.setInterpolator(context, android.R.anim.linear_interpolator); topTranslateAnimation.setFillAfter(true); top.startAnimation(topTranslateAnimation); Animation bottomTranslateAnimation=new TranslateAnimation(0, 0, 0, DensityUtil.dip2px(context,56f)); bottomTranslateAnimation.setDuration(300); bottomTranslateAnimation.setInterpolator(context, android.R.anim.linear_interpolator); bottomTranslateAnimation.setFillAfter(true); bottom.startAnimation(bottomTranslateAnimation); top.setVisibility(View.GONE); bottom.setVisibility(View.GONE); }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance) { View view = inflater.inflate(R.layout.fragment_login, container, false); ivLoginLogo = (ImageView) view.findViewById(R.id.iv_login_logo); Resources r = getResources(); float translationPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, r.getDisplayMetrics()); AlphaAnimation logoAlphaAnimation = new AlphaAnimation(0, 1); logoAlphaAnimation.setDuration(500); TranslateAnimation logoTranslateAnimation = new TranslateAnimation(0, 0, translationPx, 0); logoTranslateAnimation.setDuration(500); AnimationSet logoAnimationSet = new AnimationSet(true); logoAnimationSet.addAnimation(logoAlphaAnimation); logoAnimationSet.addAnimation(logoTranslateAnimation); ivLoginLogo.startAnimation(logoAnimationSet); btnLoginFacebook = (DCButton) view.findViewById(R.id.btn_login_facebook); btnLoginFacebook.setOnClickListener(this); btnLoginGoogle = (DCButton) view.findViewById(R.id.btn_login_google); btnLoginGoogle.setOnClickListener(this); btnLoginTwitter = (DCButton) view.findViewById(R.id.btn_login_twitter); btnLoginTwitter.setOnClickListener(this); btnLogin = (DCButton) view.findViewById(R.id.btn_login_login); btnLogin.setOnClickListener(this); tilLoginEmail = (DCTextInputLayout) view.findViewById(R.id.til_login_email); tietLoginEmail = (DCTextInputEditText) view.findViewById(R.id.tiet_login_email); tietLoginEmail.setOnFocusChangeListener(this); tilLoginPassword = (DCTextInputLayout) view.findViewById(R.id.til_login_password); tietLoginPassword = (DCTextInputEditText) view.findViewById(R.id.tiet_login_password); tvLoginForgotPassword = (DCTextView) view.findViewById(R.id.tv_login_forgot_password); tvLoginForgotPassword.setOnClickListener(this); return view; }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance) { View view = inflater.inflate(R.layout.fragment_sent_feedback, container, false); ivFeedbackTooth = (ImageView) view.findViewById(R.id.iv_feedback_tooth); tvFeedbackThankYou = (DCTextView) view.findViewById(R.id.tv_feedback_thank_you); tvFeedbackMessage = (DCTextView) view.findViewById(R.id.tv_feedback_message); Resources r = getResources(); float translationPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, r.getDisplayMetrics()); AlphaAnimation logoAnimation = new AlphaAnimation(0, 1); logoAnimation.setDuration(2000); ivFeedbackTooth.startAnimation(logoAnimation); TranslateAnimation thankYouTranslate = new TranslateAnimation(0, 0, translationPx, 0); thankYouTranslate.setDuration(1000); AlphaAnimation thankYouAlpha = new AlphaAnimation(0, 1); thankYouAlpha.setDuration(1000); AnimationSet thankYouSet = new AnimationSet(true); thankYouSet.addAnimation(thankYouTranslate); thankYouSet.addAnimation(thankYouAlpha); tvFeedbackThankYou.startAnimation(thankYouSet); AlphaAnimation messageAnimation = new AlphaAnimation(0, 1); messageAnimation.setDuration(3500); tvFeedbackMessage.startAnimation(messageAnimation); runnable = new Runnable() { @Override public void run() { if (getActivity() != null) { if (listener != null) listener.onFragmentRemoved(); getActivity().getFragmentManager().beginTransaction().remove(DCSentFeedbackFragment.this).commitAllowingStateLoss(); } } }; handler.postDelayed(runnable, 5000); return view; }
private static void ApplyHorizontalScrollAnimation(View view, boolean left, int speed) { float sign = left ? 1f : -1f; AnimationSet animationSet = new AnimationSet(true); animationSet.setRepeatCount(Animation.INFINITE); animationSet.setRepeatMode(Animation.RESTART); TranslateAnimation move = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, sign * 0.70f, Animation.RELATIVE_TO_PARENT, sign * -0.70f, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0); move.setStartOffset(0); move.setDuration(speed); move.setFillAfter(true); animationSet.addAnimation(move); view.startAnimation(animationSet); }
/** * 从控件开始的位置移动到空间顶部 */ public static TranslateAnimation moveToViewTop() { TranslateAnimation 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); return mHiddenAction; }