List of usage examples for android.view View TRANSLATION_X
Property TRANSLATION_X
To view the source code for android.view View TRANSLATION_X.
Click Source Link
translationX
functionality handled by the View#setTranslationX(float) and View#getTranslationX() methods. From source file:Main.java
public static ObjectAnimator createTranslationXAnimator(View view, float from, float to) { ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, from, to); return animator; }
From source file:Main.java
public static Animator createShakeAnimation(View target) { return ObjectAnimator.ofFloat(target, View.TRANSLATION_X, 0, 25, -25, 25, -25, 15, -15, 6, -6, 0); }
From source file:Main.java
public static ObjectAnimator nope(View view) { // int delta = view.getResources().getDimensionPixelOffset(R.dimen.spacing_medium); int delta = 40; PropertyValuesHolder pvhTranslateX = PropertyValuesHolder.ofKeyframe(View.TRANSLATION_X, Keyframe.ofFloat(0f, 0), Keyframe.ofFloat(.10f, -delta), Keyframe.ofFloat(.26f, delta), Keyframe.ofFloat(.42f, -delta), Keyframe.ofFloat(.58f, delta), Keyframe.ofFloat(.74f, -delta), Keyframe.ofFloat(.90f, delta), Keyframe.ofFloat(1f, 0f)); return ObjectAnimator.ofPropertyValuesHolder(view, pvhTranslateX).setDuration(500); }
From source file:Main.java
/** * Shake the view from left to right//w ww .ja v a 2 s. c o m * * @param view * @return */ public static ObjectAnimator leftRightShake(View view) { // int delta = view.getResources().getDimensionPixelOffset(R.dimen.spacing_medium); int delta = 40; PropertyValuesHolder pvhTranslateX = PropertyValuesHolder.ofKeyframe(View.TRANSLATION_X, Keyframe.ofFloat(0f, 0), Keyframe.ofFloat(.10f, -delta), Keyframe.ofFloat(.26f, delta), Keyframe.ofFloat(.42f, -delta), Keyframe.ofFloat(.58f, delta), Keyframe.ofFloat(.74f, -delta), Keyframe.ofFloat(.90f, delta), Keyframe.ofFloat(1f, 0f)); return ObjectAnimator.ofPropertyValuesHolder(view, pvhTranslateX).setDuration(500); }
From source file:Main.java
/** * shake x//from w w w . jav a2s. c om * * @param v * @param offset * @param duration * @param times */ public static void shakeX(View v, float offset, long duration, float times) { ObjectAnimator animator = ObjectAnimator.ofFloat(v, View.TRANSLATION_X, 0, offset); animator.setDuration(duration); animator.setInterpolator(new CycleInterpolator(times)); animator.start(); }
From source file:Main.java
/** * translation x//from w w w .ja v a2s .c om * * @param v * @param fromX * @param toX * @param duration * @param animatorListener */ public static void translationX(View v, float fromX, float toX, int duration, Animator.AnimatorListener animatorListener) { ObjectAnimator animator = ObjectAnimator.ofFloat(v, View.TRANSLATION_X, fromX, toX); animator.setDuration(duration); if (animatorListener != null) { animator.addListener(animatorListener); } animator.start(); }
From source file:com.bartoszlipinski.viewpropertyobjectanimator.ViewPropertyObjectAnimator.java
public ViewPropertyObjectAnimator translationX(float translationX) { animateProperty(View.TRANSLATION_X, translationX); return this; }
From source file:com.bartoszlipinski.viewpropertyobjectanimator.ViewPropertyObjectAnimator.java
public ViewPropertyObjectAnimator translationXBy(float translationXBy) { animatePropertyBy(View.TRANSLATION_X, translationXBy); return this; }
From source file:com.taobao.weex.ui.animation.TransformParser.java
public static Map<Property<View, Float>, Float> parseTransForm(@Nullable String rawTransform, final int width, final int height, final int viewportW) { if (!TextUtils.isEmpty(rawTransform)) { FunctionParser<Property<View, Float>, Float> parser = new FunctionParser<>(rawTransform, new FunctionParser.Mapper<Property<View, Float>, Float>() { @Override//w w w . j a v a 2s.c om public Map<Property<View, Float>, Float> map(String functionName, List<String> raw) { if (raw != null && !raw.isEmpty()) { if (wxToAndroidMap.containsKey(functionName)) { return convertParam(width, height, viewportW, wxToAndroidMap.get(functionName), raw); } } return new HashMap<>(); } private Map<Property<View, Float>, Float> convertParam(int width, int height, int viewportW, @NonNull List<Property<View, Float>> propertyList, @NonNull List<String> rawValue) { Map<Property<View, Float>, Float> result = WXDataStructureUtil .newHashMapWithExpectedSize(propertyList.size()); List<Float> convertedList = new ArrayList<>(propertyList.size()); if (propertyList.contains(View.ROTATION) || propertyList.contains(View.ROTATION_X) || propertyList.contains(View.ROTATION_Y)) { convertedList.addAll(parseRotationZ(rawValue)); } else if (propertyList.contains(View.TRANSLATION_X) || propertyList.contains(View.TRANSLATION_Y)) { convertedList .addAll(parseTranslation(propertyList, width, height, rawValue, viewportW)); } else if (propertyList.contains(View.SCALE_X) || propertyList.contains(View.SCALE_Y)) { convertedList.addAll(parseScale(propertyList.size(), rawValue)); } else if (propertyList.contains(CameraDistanceProperty.getInstance())) { convertedList.add(parseCameraDistance(rawValue)); } if (propertyList.size() == convertedList.size()) { for (int i = 0; i < propertyList.size(); i++) { result.put(propertyList.get(i), convertedList.get(i)); } } return result; } private List<Float> parseScale(int size, @NonNull List<String> rawValue) { List<Float> convertedList = new ArrayList<>(rawValue.size() * 2); List<Float> rawFloat = new ArrayList<>(rawValue.size()); for (String item : rawValue) { rawFloat.add(WXUtils.fastGetFloat(item)); } convertedList.addAll(rawFloat); if (size != 1 && rawValue.size() == 1) { convertedList.addAll(rawFloat); } return convertedList; } private @NonNull List<Float> parseRotationZ(@NonNull List<String> rawValue) { List<Float> convertedList = new ArrayList<>(1); int suffix; for (String raw : rawValue) { if ((suffix = raw.lastIndexOf(DEG)) != -1) { convertedList.add(WXUtils.fastGetFloat(raw.substring(0, suffix))); } else { convertedList.add((float) Math.toDegrees(Double.parseDouble(raw))); } } return convertedList; } /** * As "translate(50%, 25%)" or "translate(25px, 30px)" both are valid, * parsing translate is complicated than other method. * Add your waste time here if you try to optimize this method like {@link #parseScale(int, List)} * Time: 0.5h */ private List<Float> parseTranslation(List<Property<View, Float>> propertyList, int width, int height, @NonNull List<String> rawValue, int viewportW) { List<Float> convertedList = new ArrayList<>(2); String first = rawValue.get(0); if (propertyList.size() == 1) { parseSingleTranslation(propertyList, width, height, convertedList, first, viewportW); } else { parseDoubleTranslation(width, height, rawValue, convertedList, first, viewportW); } return convertedList; } private void parseSingleTranslation(List<Property<View, Float>> propertyList, int width, int height, List<Float> convertedList, String first, int viewportW) { if (propertyList.contains(View.TRANSLATION_X)) { convertedList.add(parsePercentOrPx(first, width, viewportW)); } else if (propertyList.contains(View.TRANSLATION_Y)) { convertedList.add(parsePercentOrPx(first, height, viewportW)); } } private void parseDoubleTranslation(int width, int height, @NonNull List<String> rawValue, List<Float> convertedList, String first, int viewportW) { String second; if (rawValue.size() == 1) { second = first; } else { second = rawValue.get(1); } convertedList.add(parsePercentOrPx(first, width, viewportW)); convertedList.add(parsePercentOrPx(second, height, viewportW)); } private Float parseCameraDistance(List<String> rawValue) { float ret = Float.MAX_VALUE; if (rawValue.size() == 1) { float value = WXViewUtils.getRealPxByWidth(WXUtils.getFloat(rawValue.get(0)), viewportW); float scale = WXEnvironment.getApplication().getResources() .getDisplayMetrics().density; if (!Float.isNaN(value) && value > 0) { ret = value * scale; } } return ret; } }); return parser.parse(); } return new LinkedHashMap<>(); }
From source file:de.dreier.mytargets.utils.transitions.FabTransform.java
@Override public Animator createAnimator(@NonNull final ViewGroup sceneRoot, final TransitionValues startValues, final TransitionValues endValues) { if (startValues == null || endValues == null) { return null; }//from www. java2 s . c o m final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS); final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS); final boolean fromFab = endBounds.width() > startBounds.width(); final View view = endValues.view; final Rect dialogBounds = fromFab ? endBounds : startBounds; final Rect fabBounds = fromFab ? startBounds : endBounds; final Interpolator fastOutSlowInInterpolator = new FastOutSlowInInterpolator(); final long duration = getDuration(); final long halfDuration = duration / 2; final long twoThirdsDuration = duration * 2 / 3; if (!fromFab) { // Force measure / layout the dialog back to it's original bounds view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY), makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY)); view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom); } final int translationX = startBounds.centerX() - endBounds.centerX(); final int translationY = startBounds.centerY() - endBounds.centerY(); if (fromFab) { view.setTranslationX(translationX); view.setTranslationY(translationY); } // Add a color overlay to fake appearance of the FAB final ColorDrawable fabColor = new ColorDrawable(color); fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height()); if (!fromFab) { fabColor.setAlpha(0); } view.getOverlay().add(fabColor); // Add an icon overlay again to fake the appearance of the FAB final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate(); final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2; final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2; fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(), iconTop + fabIcon.getIntrinsicHeight()); if (!fromFab) { fabIcon.setAlpha(0); } view.getOverlay().add(fabIcon); // Circular clip from/to the FAB size final Animator circularReveal; if (fromFab) { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, startBounds.width() / 2, (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2)); circularReveal.setInterpolator(new FastOutLinearInInterpolator()); } else { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2), endBounds.width() / 2); circularReveal.setInterpolator(new LinearOutSlowInInterpolator()); // Persist the end clip i.e. stay at FAB size after the reveal has run circularReveal.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { view.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { final int left = (view.getWidth() - fabBounds.width()) / 2; final int top = (view.getHeight() - fabBounds.height()) / 2; outline.setOval(left, top, left + fabBounds.width(), top + fabBounds.height()); view.setClipToOutline(true); } }); } }); } circularReveal.setDuration(duration); // Translate to end position along an arc final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y, fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0) : getPathMotion().getPath(0, 0, -translationX, -translationY)); translate.setDuration(duration); translate.setInterpolator(fastOutSlowInInterpolator); // Fade contents of non-FAB view in/out List<Animator> fadeContents = null; if (view instanceof ViewGroup) { final ViewGroup vg = ((ViewGroup) view); fadeContents = new ArrayList<>(vg.getChildCount()); for (int i = vg.getChildCount() - 1; i >= 0; i--) { final View child = vg.getChildAt(i); final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f); if (fromFab) { child.setAlpha(0f); } fade.setDuration(twoThirdsDuration); fade.setInterpolator(fastOutSlowInInterpolator); fadeContents.add(fade); } } // Fade in/out the fab color & icon overlays final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255); final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255); if (!fromFab) { colorFade.setStartDelay(halfDuration); iconFade.setStartDelay(halfDuration); } colorFade.setDuration(halfDuration); iconFade.setDuration(halfDuration); colorFade.setInterpolator(fastOutSlowInInterpolator); iconFade.setInterpolator(fastOutSlowInInterpolator); // Work around issue with elevation shadows. At the end of the return transition the shared // element's shadow is drawn twice (by each activity) which is jarring. This workaround // still causes the shadow to snap, but it's better than seeing it double drawn. Animator elevation = null; if (!fromFab) { elevation = ObjectAnimator.ofFloat(view, View.TRANSLATION_Z, -view.getElevation()); elevation.setDuration(duration); elevation.setInterpolator(fastOutSlowInInterpolator); } // Run all animations together final AnimatorSet transition = new AnimatorSet(); transition.playTogether(circularReveal, translate, colorFade, iconFade); transition.playTogether(fadeContents); if (elevation != null) { transition.play(elevation); } if (fromFab) { transition.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { // Clean up view.getOverlay().clear(); } }); } return new NoPauseAnimator(transition); }