Java Code Examples for android.view.View#setTranslationZ()

The following examples show how to use android.view.View#setTranslationZ() . 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: ActivityTransitionCoordinator.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
protected static void setOriginalSharedElementState(ArrayList<View> sharedElements,
        ArrayList<SharedElementOriginalState> originalState) {
    for (int i = 0; i < originalState.size(); i++) {
        View view = sharedElements.get(i);
        SharedElementOriginalState state = originalState.get(i);
        if (view instanceof ImageView && state.mScaleType != null) {
            ImageView imageView = (ImageView) view;
            imageView.setScaleType(state.mScaleType);
            if (state.mScaleType == ImageView.ScaleType.MATRIX) {
              imageView.setImageMatrix(state.mMatrix);
            }
        }
        view.setElevation(state.mElevation);
        view.setTranslationZ(state.mTranslationZ);
        int widthSpec = View.MeasureSpec.makeMeasureSpec(state.mMeasuredWidth,
                View.MeasureSpec.EXACTLY);
        int heightSpec = View.MeasureSpec.makeMeasureSpec(state.mMeasuredHeight,
                View.MeasureSpec.EXACTLY);
        view.measure(widthSpec, heightSpec);
        view.layout(state.mLeft, state.mTop, state.mRight, state.mBottom);
    }
}
 
Example 2
Source File: Helper.java    From backstack with Apache License 2.0 6 votes vote down vote up
/**
 * Helper function to disable a ViewGroup and all it's children. This draws a new view with z-ordering of integer max
 * that consumes all touch events.
 * @param viewGroup
 */
public static void disable(ViewGroup viewGroup){
    View view = new View(viewGroup.getContext());
    viewGroup.addView(view);
    view.setTag(DISABLE);

    ViewGroup.LayoutParams params = view.getLayoutParams();
    params.height = MATCH_PARENT;
    params.width = MATCH_PARENT;
    view.setLayoutParams(params);

    view.setClickable(true);
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(Color.TRANSPARENT);

    if (Build.VERSION.SDK_INT >= 21) {
        view.setTranslationZ(Integer.MAX_VALUE);
    }
    viewGroup.bringChildToFront(view);
}
 
Example 3
Source File: ExpandableLayoutManager.java    From OmegaRecyclerView with MIT License 6 votes vote down vote up
@Override
public void addView(View child) {
    child.setAlpha(1f);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        child.setTranslationZ(0f);
    }

    ExpandedRecyclerView.ViewHolder holder = ExpandedRecyclerView.getChildViewHolderInt(child);
    if (holder instanceof OmegaExpandableRecyclerView.Adapter.ChildViewHolder) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            child.setTranslationZ(DEFAULT_CHILD_Z);
        }
        int adapterPosition = holder.getAdapterPosition();
        if (mAddedRange.contains(adapterPosition)) {
            ((OmegaExpandableRecyclerView.Adapter.ChildViewHolder) holder).contentView.setAlpha(0f);
        }
    }

    super.addView(child);
}
 
Example 4
Source File: FabTransformationBehavior.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@TargetApi(VERSION_CODES.LOLLIPOP)
private void createElevationAnimation(
    View dependency,
    @NonNull View child,
    boolean expanded,
    boolean currentlyAnimating,
    @NonNull FabTransformationSpec spec,
    @NonNull List<Animator> animations,
    List<AnimatorListener> unusedListeners) {
  float translationZ = ViewCompat.getElevation(child) - ViewCompat.getElevation(dependency);
  Animator animator;

  if (expanded) {
    if (!currentlyAnimating) {
      child.setTranslationZ(-translationZ);
    }
    animator = ObjectAnimator.ofFloat(child, View.TRANSLATION_Z, 0f);
  } else {
    animator = ObjectAnimator.ofFloat(child, View.TRANSLATION_Z, -translationZ);
  }

  MotionTiming timing = spec.timings.getTiming("elevation");
  timing.apply(animator);
  animations.add(animator);
}
 
Example 5
Source File: ChangeTransform.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static void setTransforms(View view, float translationX, float translationY,
        float translationZ, float scaleX, float scaleY, float rotationX,
        float rotationY, float rotationZ) {
    view.setTranslationX(translationX);
    view.setTranslationY(translationY);
    view.setTranslationZ(translationZ);
    view.setScaleX(scaleX);
    view.setScaleY(scaleY);
    view.setRotationX(rotationX);
    view.setRotationY(rotationY);
    view.setRotation(rotationZ);
}
 
Example 6
Source File: GalleryTransformer.java    From Pixiv-Shaft with MIT License 5 votes vote down vote up
@Override
public void transformPage(View page, float position) {
    float scale= 1 - (Math.abs(position) * 0.25f);
    page.setScaleX(scale);
    page.setScaleY(scale);

    if (Math.abs(position) > 0.1) {
        page.setTranslationZ(-Math.abs(position));
    }else {
        page.setTranslationZ(position);
    }
    page.setTranslationX(-50 * position);
}
 
Example 7
Source File: FlipLayout.java    From FlipLayout with Apache License 2.0 5 votes vote down vote up
private void restoreView(View v) {
    v.setVisibility(endVisibility);
    v.setPivotY(v.getHeight() / 2);
    v.setPivotX(v.getWidth() / 2);
    v.setRotation(0);
    v.setRotationX(0);
    v.setRotationY(0);
    v.setTranslationX(0);
    v.setTranslationY(0);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        v.setTranslationZ(0);
    }
}
 
Example 8
Source File: ViewCompatLollipop.java    From letv with Apache License 2.0 4 votes vote down vote up
public static void setTranslationZ(View view, float translationZ) {
    view.setTranslationZ(translationZ);
}
 
Example 9
Source File: DuoDrawerLayout.java    From duo-navigation-drawer with Apache License 2.0 4 votes vote down vote up
/**
 * Adds a touch interceptor to the layout when needed.
 * The interceptor wil take care of touch events occurring
 * on the content view when the drawer is open.
 */
private void addTouchInterceptor() {
    View touchInterceptor = mLayoutInflater.inflate(R.layout.duo_overlay, this, false);
    touchInterceptor.setTag(TAG_OVERLAY);
    touchInterceptor.setOnTouchListener(new OnTouchListener() {
        float startX;
        float startY;

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (mLockMode != LOCK_MODE_LOCKED_OPEN) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        startX = event.getX();
                        startY = event.getY();
                        break;
                    case MotionEvent.ACTION_UP:
                        float endX = event.getX();
                        float endY = event.getY();

                        if (touchIsClick(startX, endX, startY, endY)) {
                            closeDrawer();
                        }
                        break;
                    case MotionEvent.ACTION_MOVE:
                        mViewDragCallback.mIsEdgeDrag = true;
                        int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
                        mViewDragHelper.captureChildView(mContentView, pointerIndex);
                        break;
                }
                return true;
            } else return true;
        }
    });


    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        touchInterceptor.setTranslationZ(MAX_ATTRIBUTE_MULTIPLIER);
    }

    addView(touchInterceptor);
}
 
Example 10
Source File: SwipeStack.java    From SwipeStack with Apache License 2.0 4 votes vote down vote up
private void reorderItems() {
    for (int x = 0; x < getChildCount(); x++) {
        View childView = getChildAt(x);
        int topViewIndex = getChildCount() - 1;

        int distanceToViewAbove = (topViewIndex * mViewSpacing) - (x * mViewSpacing);
        int newPositionX = (getWidth() - childView.getMeasuredWidth()) / 2;
        int newPositionY = distanceToViewAbove + getPaddingTop();

        childView.layout(
                newPositionX,
                getPaddingTop(),
                newPositionX + childView.getMeasuredWidth(),
                getPaddingTop() + childView.getMeasuredHeight());

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            childView.setTranslationZ(x);
        }

        boolean isNewView = (boolean) childView.getTag(R.id.new_view);
        float scaleFactor = (float) Math.pow(mScaleFactor, getChildCount() - x);

        if (x == topViewIndex) {
            mSwipeHelper.unregisterObservedView();
            mTopView = childView;
            mSwipeHelper.registerObservedView(mTopView, newPositionX, newPositionY);
        }

        if (!mIsFirstLayout) {

            if (isNewView) {
                childView.setTag(R.id.new_view, false);
                childView.setAlpha(0);
                childView.setY(newPositionY);
                childView.setScaleY(scaleFactor);
                childView.setScaleX(scaleFactor);
            }

            childView.animate()
                    .y(newPositionY)
                    .scaleX(scaleFactor)
                    .scaleY(scaleFactor)
                    .alpha(1)
                    .setDuration(mAnimationDuration);

        } else {
            childView.setTag(R.id.new_view, false);
            childView.setY(newPositionY);
            childView.setScaleY(scaleFactor);
            childView.setScaleX(scaleFactor);
        }
    }
}
 
Example 11
Source File: SwipeCards.java    From UltimateSwipeTool with Apache License 2.0 4 votes vote down vote up
private void reorderItems() {
    for (int x = 0; x < getChildCount(); x++) {
        View childView = getChildAt(x);
        int topViewIndex = getChildCount() - 1;

        int distanceToViewAbove = (topViewIndex * mViewSpacing) - (x * mViewSpacing);
        int newPositionX = (getWidth() - childView.getMeasuredWidth()) / 2;
        int newPositionY = distanceToViewAbove + getPaddingTop();

        childView.layout(
                newPositionX,
                getPaddingTop(),
                newPositionX + childView.getMeasuredWidth(),
                getPaddingTop() + childView.getMeasuredHeight());

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            childView.setTranslationZ(x);
        }

        boolean isNewView = (boolean) childView.getTag(R.id.new_view);
        float scaleFactor = (float) Math.pow(mScaleFactor, getChildCount() - x);

        if (x == topViewIndex) {
            mSwipeCardsHelper.unregisterObservedView();
            mTopView = childView;
            mSwipeCardsHelper.registerObservedView(mTopView, newPositionX, newPositionY);
        }

        if (!mIsFirstLayout) {

            if (isNewView) {
                childView.setTag(R.id.new_view, false);
                childView.setAlpha(0);
                childView.setY(newPositionY);
                childView.setScaleY(scaleFactor);
                childView.setScaleX(scaleFactor);
            }

            childView.animate()
                    .y(newPositionY)
                    .scaleX(scaleFactor)
                    .scaleY(scaleFactor)
                    .alpha(1)
                    .setDuration(mAnimationDuration);

        } else {
            childView.setTag(R.id.new_view, false);
            childView.setY(newPositionY);
            childView.setScaleY(scaleFactor);
            childView.setScaleX(scaleFactor);
        }
    }
}
 
Example 12
Source File: ViewCompatApi21.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public static void setTranslationZ(View view, float translationZ) {
    view.setTranslationZ(translationZ);
}
 
Example 13
Source File: DynamicAnimation.java    From CircularReveal with MIT License 4 votes vote down vote up
@Override
public void setValue(View view, float value) {
  if (isZSupported()) {
    view.setTranslationZ(value);
  }
}
 
Example 14
Source File: ViewUtilsLollipop.java    From Transitions-Everywhere with Apache License 2.0 4 votes vote down vote up
@Override
public void setTranslationZ(@NonNull View view, float z) {
    view.setTranslationZ(z);
}