Java Code Examples for android.view.View#setTranslationY()
The following examples show how to use
android.view.View#setTranslationY() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DepthPageTransformer.java From OmegaRecyclerView with MIT License | 6 votes |
@Override public void transformItem(View view, float position, boolean isHorizontal, int scrolled) { if (position < 0f) { view.setTranslationX(0f); view.setTranslationY(0f); view.setScaleX(1f); view.setScaleY(1f); view.setAlpha(1f); return; } float scaleFactor = mMinScale + (1 - mMinScale) * (1 - Math.abs(position)); view.setAlpha(1 - position); view.setScaleX(scaleFactor); view.setScaleY(scaleFactor); if (isHorizontal) { view.setTranslationX(view.getWidth() * -position); } else { view.setTranslationY(view.getHeight() * -position); } }
Example 2
Source File: LoadAdapter.java From NBAPlus with Apache License 2.0 | 6 votes |
protected void runEnterAnimation(View view, final int position) { if (position > lastAnimatedPosition) { lastAnimatedPosition = position; view.setTranslationY(NumericalUtil.getScreenHeight(mContext)); view.animate() .translationY(0) .setInterpolator(new DecelerateInterpolator(3.0f)) .setDuration(ANIMATED_ITEMS_DURATION) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (position == mAnimateEndCount||position>=getItemCount()-1) { AppService.getInstance().getBus().post(new NewsAnimatEndEvent()); } } }) .start(); } }
Example 3
Source File: CommentContentsLayout.java From star-zone-android with Apache License 2.0 | 6 votes |
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if (mode == Mode.NORMAL) return; int height = getMeasuredHeight(); height = drawWrapButton() ? height + showMoreTextHeight : height; if (getChildCount() <= mWrapCount) { setMeasuredDimension(widthMeasureSpec, height); return; } int notWrapContentHeight = 0; for (int i = 0; i < mWrapCount; i++) { notWrapContentHeight += getChildAt(i).getMeasuredHeight(); } notWrapContentHeight = height - notWrapContentHeight; float delay = notWrapContentHeight - Math.round(notWrapContentHeight * curExpandValue); for (int i = mWrapCount; i < getChildCount(); i++) { View child = getChildAt(i); if (child.getVisibility() != View.GONE) { Log.i(TAG, "onMeasure: " + delay); child.setTranslationY(-delay); } } setMeasuredDimension(widthMeasureSpec, (int) (height - delay)); }
Example 4
Source File: ViewAnimationUtils.java From PersistentSearchView with Apache License 2.0 | 6 votes |
/** * Lifting view * * @param view The animation target * @param baseRotation initial Rotation X in 3D space * @param duration aniamtion duration * @param startDelay start delay before animation begin */ @Deprecated public static void liftingFromBottom(View view, float baseRotation, int duration, int startDelay){ view.setRotationX(baseRotation); view.setTranslationY(view.getHeight() / 3); view .animate() .setInterpolator(new AccelerateDecelerateInterpolator()) .setDuration(duration) .setStartDelay(startDelay) .rotationX(0) .translationY(0) .start(); }
Example 5
Source File: ItemTouchUIUtilImpl.java From Telegram with GNU General Public License v2.0 | 6 votes |
@Override public void onDraw(Canvas c, RecyclerView recyclerView, View view, float dX, float dY, int actionState, boolean isCurrentlyActive) { if (Build.VERSION.SDK_INT >= 21) { if (isCurrentlyActive) { Object originalElevation = view.getTag(); if (originalElevation == null) { originalElevation = ViewCompat.getElevation(view); float newElevation = 1f + findMaxElevation(recyclerView, view); ViewCompat.setElevation(view, newElevation); view.setTag(originalElevation); } } } view.setTranslationX(dX); view.setTranslationY(dY); }
Example 6
Source File: BaseTransformer.java From android-viewpager-transformers with Apache License 2.0 | 6 votes |
/** * Called each {@link #transformPage(android.view.View, float)} before {{@link #onTransform(android.view.View, float)} is called. * * @param view * @param position */ protected void onPreTransform(View view, float position) { final float width = view.getWidth(); view.setRotationX(0); view.setRotationY(0); view.setRotation(0); view.setScaleX(1); view.setScaleY(1); view.setPivotX(0); view.setPivotY(0); view.setTranslationY(0); view.setTranslationX(isPagingEnabled() ? 0f : -width * position); if (hideOffscreenPages()) { view.setAlpha(position <= -1f || position >= 1f ? 0f : 1f); } else { view.setAlpha(1f); } }
Example 7
Source File: ABaseTransformer.java From Banner with Apache License 2.0 | 6 votes |
protected void onPreTransform(View page, float position) { final float width = page.getWidth(); page.setRotationX(0); page.setRotationY(0); page.setRotation(0); page.setScaleX(1); page.setScaleY(1); page.setPivotX(0); page.setPivotY(0); page.setTranslationY(0); page.setTranslationX(isPagingEnabled() ? 0f : -width * position); if (hideOffscreenPages()) { page.setAlpha(position <= -1f || position >= 1f ? 0f : 1f); // page.setEnabled(false); } else { // page.setEnabled(true); page.setAlpha(1f); } }
Example 8
Source File: ActivitySlidingBackConsumer.java From SmartSwipe with Apache License 2.0 | 5 votes |
@Override protected void onDisplayDistanceChanged(int distanceXToDisplay, int distanceYToDisplay, int dx, int dy) { if (!mActivityTranslucentUtil.isTranslucent()) { return; } if (mPreviousActivityContentView != null) { int translation = 0; switch (mDirection) { case DIRECTION_LEFT: translation = initTranslation + (int) (mWidth * mProgress * mRelativeMoveFactor); break; case DIRECTION_RIGHT: translation = initTranslation - (int) (mWidth * mProgress * mRelativeMoveFactor); break; case DIRECTION_TOP: translation = initTranslation + (int) (mHeight * mProgress * mRelativeMoveFactor); break; case DIRECTION_BOTTOM: translation = initTranslation - (int) (mHeight * mProgress * mRelativeMoveFactor); break; default: } movePreviousActivityContentView(translation); } boolean horizontal = (mDirection & DIRECTION_HORIZONTAL) > 0; View contentView = mWrapper.getContentView(); if (contentView != null) { if (horizontal) { contentView.setTranslationX(distanceXToDisplay); } else { contentView.setTranslationY(distanceYToDisplay); } } layoutScrimView(); }
Example 9
Source File: HeaderBehavior.java From CoordinatorLayoutExample with Apache License 2.0 | 5 votes |
@Override public void onNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull View child, @NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type) { if (!mCouldScroollOpen) { if (isClosed(child)) { return; } } if (mIsFling || dyUnconsumed > 0) { return; } logD(TAG, "onNestedScroll: dyConsumed=" + dyConsumed + " dyUnconsumed= " + dyUnconsumed + "mIsFling " + mIsFling); float translationY = child.getTranslationY() - dyUnconsumed; int maxHeadTranslateY = 0; if (translationY > maxHeadTranslateY) { translationY = maxHeadTranslateY; } logD(TAG, "onNestedScroll: translationY=" + translationY); if (child.getTranslationY() != translationY) { onScrollChange(type, (int) translationY); child.setTranslationY(translationY); } }
Example 10
Source File: Instrument.java From CloudReader with Apache License 2.0 | 5 votes |
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); } }
Example 11
Source File: AnimatableIconView.java From GeometricWeather with GNU Lesser General Public License v3.0 | 5 votes |
private void resetView(View view) { view.setAlpha(1f); view.setScaleX(1f); view.setScaleY(1f); view.setRotation(0f); view.setRotationX(0f); view.setRotationY(0f); view.setTranslationX(0f); view.setTranslationY(0f); }
Example 12
Source File: FastScroller.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Positions the thumb and preview widgets. * * @param position The position, between 0 and 1, along the track at which * to place the thumb. */ private void setThumbPos(float position) { final float thumbMiddle = position * mThumbRange + mThumbOffset; mThumbImage.setTranslationY(thumbMiddle - mThumbImage.getHeight() / 2f); final View previewImage = mPreviewImage; final float previewHalfHeight = previewImage.getHeight() / 2f; final float previewPos; switch (mOverlayPosition) { case OVERLAY_AT_THUMB: previewPos = thumbMiddle; break; case OVERLAY_ABOVE_THUMB: previewPos = thumbMiddle - previewHalfHeight; break; case OVERLAY_FLOATING: default: previewPos = 0; break; } // Center the preview on the thumb, constrained to the list bounds. final Rect container = mContainerRect; final int top = container.top; final int bottom = container.bottom; final float minP = top + previewHalfHeight; final float maxP = bottom - previewHalfHeight; final float previewMiddle = MathUtils.constrain(previewPos, minP, maxP); final float previewTop = previewMiddle - previewHalfHeight; previewImage.setTranslationY(previewTop); mPrimaryText.setTranslationY(previewTop); mSecondaryText.setTranslationY(previewTop); }
Example 13
Source File: FABSnackbarBehavior.java From FABsMenu with Apache License 2.0 | 5 votes |
/** * Animate FAB on snackbar change. */ private void updateFabTranslationForSnackbar(CoordinatorLayout parent, View fab, View snackbar) { final float translationY = getFabTranslationYForSnackbar(parent, fab); if (translationY != this.mTranslationY) { ViewCompat.animate(fab).cancel(); if (Math.abs(translationY - this.mTranslationY) == (float) snackbar.getHeight()) { ViewCompat.animate(fab).translationY(translationY).setInterpolator( new FastOutSlowInInterpolator()); } else { fab.setTranslationY(translationY); } this.mTranslationY = translationY; } }
Example 14
Source File: FloatingMusicMenu.java From FloatingMusicMenu with Apache License 2.0 | 5 votes |
/** * 摆放朝下展开方向的子控件位置 */ private void onDownDirectionLayout(int l, int t, int r, int b) { int centerX = (r - l) / 2; int offsetY = SHADOW_OFFSET; View rootView = getChildAt(getChildCount() - 1); rootView.layout(centerX - rootView.getMeasuredWidth() / 2, offsetY, centerX + rootView.getMeasuredWidth() / 2, offsetY + rootView.getMeasuredHeight()); offsetY += rootView.getMeasuredHeight() + buttonInterval; for (int i = 0; i < getChildCount() - 1; i++) { View child = getChildAt(i); if (child.getVisibility() == GONE) continue; int width = child.getMeasuredWidth(); int height = child.getMeasuredHeight(); child.layout(centerX - width / 2, offsetY, centerX + width / 2, offsetY + height); float collapsedTranslation = -offsetY; float expandedTranslation = 0f; child.setTranslationY(isExpanded ? expandedTranslation : collapsedTranslation); child.setAlpha(isExpanded ? 1f : 0f); MenuLayoutParams params = (MenuLayoutParams) child.getLayoutParams(); params.collapseDirAnim.setFloatValues(expandedTranslation, collapsedTranslation); params.expandDirAnim.setFloatValues(collapsedTranslation, expandedTranslation); params.collapseDirAnim.setProperty(View.TRANSLATION_Y); params.expandDirAnim.setProperty(View.TRANSLATION_Y); params.setAnimationsTarget(child); offsetY += height + buttonInterval; } }
Example 15
Source File: ViewAnimationUtilties.java From Nibo with MIT License | 5 votes |
/** * Lifting view * * @param view The animation target * @param baseRotation initial Rotation X in 3D space * @param duration aniamtion duration */ @Deprecated public static void liftingFromBottom(View view, float baseRotation, int duration){ view.setRotationX(baseRotation); view.setTranslationY(view.getHeight() / 3); view .animate() .setInterpolator(new AccelerateDecelerateInterpolator()) .setDuration(duration) .rotationX(0) .translationY(0) .start(); }
Example 16
Source File: Instrument.java From stynico with MIT License | 5 votes |
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); } }
Example 17
Source File: BezierTransition.java From CrazyDaily with Apache License 2.0 | 5 votes |
@Override public void set(View view, PointF value) { int x = Math.round(value.x); int y = Math.round(value.y); int startX = Math.round(endPoint.x); int startY = Math.round(endPoint.y); int transY = y - startY; int transX = x - startX; view.setTranslationX(transX); view.setTranslationY(transY); }
Example 18
Source File: MoveUpBehavior.java From AndroidPlusJava with GNU General Public License v3.0 | 4 votes |
@Override public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) { float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight()); child.setTranslationY(translationY); return true; }
Example 19
Source File: FabTransformationBehavior.java From material-components-android with Apache License 2.0 | 4 votes |
private void createTranslationAnimation( @NonNull View dependency, @NonNull View child, boolean expanded, boolean currentlyAnimating, @NonNull FabTransformationSpec spec, @NonNull List<Animator> animations, List<AnimatorListener> unusedListeners, @NonNull RectF childBounds) { float translationX = calculateTranslationX(dependency, child, spec.positioning); float translationY = calculateTranslationY(dependency, child, spec.positioning); ValueAnimator translationXAnimator; ValueAnimator translationYAnimator; Pair<MotionTiming, MotionTiming> motionTiming = calculateMotionTiming(translationX, translationY, expanded, spec); MotionTiming translationXTiming = motionTiming.first; MotionTiming translationYTiming = motionTiming.second; if (expanded) { if (!currentlyAnimating) { child.setTranslationX(-translationX); child.setTranslationY(-translationY); } translationXAnimator = ObjectAnimator.ofFloat(child, View.TRANSLATION_X, 0f); translationYAnimator = ObjectAnimator.ofFloat(child, View.TRANSLATION_Y, 0f); calculateChildVisibleBoundsAtEndOfExpansion( child, spec, translationXTiming, translationYTiming, -translationX, -translationY, 0f, 0f, childBounds); } else { translationXAnimator = ObjectAnimator.ofFloat(child, View.TRANSLATION_X, -translationX); translationYAnimator = ObjectAnimator.ofFloat(child, View.TRANSLATION_Y, -translationY); } translationXTiming.apply(translationXAnimator); translationYTiming.apply(translationYAnimator); animations.add(translationXAnimator); animations.add(translationYAnimator); }
Example 20
Source File: MoveUpwardBehavior.java From EdXposedManager with GNU General Public License v3.0 | 4 votes |
@Override public boolean onDependentViewChanged(@NonNull CoordinatorLayout parent, View child, @NonNull View dependency) { float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight()); child.setTranslationY(translationY); return true; }