Java Code Examples for androidx.core.view.ViewCompat#setTranslationZ()

The following examples show how to use androidx.core.view.ViewCompat#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: BrowserActivity.java    From EFRConnect-android with Apache License 2.0 6 votes vote down vote up
private void animateToolbarOpen(int openPercentHeight, int duration) {
    ValueAnimator animator = ValueAnimator.ofInt(0, percentHeightToPx(openPercentHeight)).setDuration(duration);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            Integer value = (Integer) animation.getAnimatedValue();
            frameLayout.getLayoutParams().height = value.intValue();
            frameLayout.requestLayout();
        }
    });

    frameLayout.setVisibility(View.VISIBLE);
    ViewCompat.setTranslationZ(frameLayoutContainerRL, 5f);
    AnimatorSet set = new AnimatorSet();
    set.play(animator);
    set.setInterpolator(new AccelerateDecelerateInterpolator());
    set.start();
}
 
Example 2
Source File: DeviceServicesActivity.java    From EFRConnect-android with Apache License 2.0 6 votes vote down vote up
private void animateToolbarOpen(int openPercentHeight, int duration) {
    ValueAnimator animator = ValueAnimator.ofInt(0, percentHeightToPx(openPercentHeight)).setDuration(duration);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            Integer value = (Integer) animation.getAnimatedValue();
            frameLayout.getLayoutParams().height = value;
            frameLayout.requestLayout();
        }
    });

    frameLayout.setVisibility(View.VISIBLE);
    ViewCompat.setTranslationZ(frameLayoutContainerRL, 5f);
    AnimatorSet set = new AnimatorSet();
    set.play(animator);
    set.setInterpolator(new AccelerateDecelerateInterpolator());
    set.start();
}
 
Example 3
Source File: MaterialShadowContainerView.java    From android-materialshadowninepatch with Apache License 2.0 6 votes vote down vote up
private void updateShadowLevelNative(float translationZ, float elevation, boolean force) {
    if (force) {
        mCurrentSpotShadowDrawable1 = null;
        mCurrentSpotShadowDrawable1ResId = 0;
        mCurrentSpotShadowDrawable2 = null;
        mCurrentSpotShadowDrawable2ResId = 0;
        mCurrentAmbientShadowDrawable1 = null;
        mCurrentAmbientShadowDrawable1ResId = 0;
        mCurrentAmbientShadowDrawable2 = null;
        mCurrentAmbientShadowDrawable2ResId = 0;
        updateWillNotDraw();
    }

    final View childView = (getChildCount() > 0) ? getChildAt(0) : null;

    if (childView != null) {
        ViewCompat.setTranslationZ(childView, translationZ);
        ViewCompat.setElevation(childView, elevation);
    }
}
 
Example 4
Source File: Animer.java    From Animer with Apache License 2.0 4 votes vote down vote up
@Override
public void setValue(View view, float value) {
    ViewCompat.setTranslationZ(view, value);
}
 
Example 5
Source File: MineFragment.java    From FastLib with Apache License 2.0 4 votes vote down vote up
@Override
public void initView(Bundle savedInstanceState) {
    mImagePickerHelper = new ImagePickerHelper(mContext);
    mIvHead = mStvInfo.getLeftIconIV();
    GlideManager.loadCircleImg("https://avatars0.githubusercontent.com/u/19605922?s=460&v=4", mIvHead);
    LoggerManager.d("imageHeight:" + mIvHead.getLayoutParams().height + ";screenWidth:" + SizeUtil.getScreenWidth());
    SpanTool.getBuilder(mStvInfo.getLeftString())
            .append("https://github.com/AriesHoo")
            .setUnderline()
            .setForegroundColor(Color.BLUE)
            .setBoldItalic()
            .into(mStvInfo.getLeftTextView());
    SpanTool.getBuilder(mStvInfo.getLeftBottomString())
            .append("http://www.jianshu.com/u/a229eee96115")
            .setUnderline()
            .setForegroundColor(Color.BLUE)
            .setBoldItalic()
            .into(mStvInfo.getLeftBottomTextView());

    mStvInfo.setLeftTvClickListener(() -> WebViewActivity.start(mContext, "https://github.com/AriesHoo"));
    mStvInfo.setLeftBottomTvClickListener(() -> WebViewActivity.start(mContext, "http://www.jianshu.com/u/a229eee96115"));
    mStvInfo.getLeftBottomTextView().setGravity(Gravity.LEFT);
    ViewCompat.setElevation(mStvInfo, getResources().
            getDimension(R.dimen.dp_elevation));
    ViewCompat.setTranslationZ(mStvInfo, 3f);
    if (!App.isSupportElevation()) {
        mStvInfo.setShapeStrokeWidth(getResources().getDimensionPixelSize(R.dimen.dp_line_size))
                .setShapeStrokeColor(ContextCompat.getColor(mContext, R.color.colorLineGray))
                .useShape();
    }

    mIvHead.setOnClickListener(v -> mImagePickerHelper.selectPicture(1000, (requestCode, list) -> {
        if (list == null || list.size() == 0 || requestCode != 1000) {
            return;
        }
        GlideManager.loadCircleImg(list.get(0), mIvHead);
    }));

    mStvUpdate.setRightString("当前版本:V" + FastUtil.getVersionName(mContext));
    //根据屏幕宽度重新调整背景图
    int heightCover = SizeUtil.getScreenWidth() * 1 / 2;
    ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) mTvCover.getLayoutParams();
    if (params != null) {
        params.height = heightCover;
    }
    ViewGroup.MarginLayoutParams margin = (ViewGroup.MarginLayoutParams) mStvInfo.getLayoutParams();
    if (margin != null) {
        margin.topMargin = heightCover - SizeUtil.dp2px(20);
    }
    mTitleBarViewHelper = new TitleBarViewHelper(mContext)
            .setTitleBarView(mTitleBar)
            .setOverScrollView(mSvContainer)
            .setShowTextEnable(true)
            .setMaxHeight(heightCover)
            .setOnScrollListener(new TitleBarViewHelper.OnScrollListener() {
                @Override
                public void onScrollChange(int alpha, boolean isLightMode) {
                    mIsLight = isLightMode;
                }
            });
    LoggerManager.i("initView_getParent:" + mContentView.getParent() + ";rootView:" + mContentView.getRootView());
}
 
Example 6
Source File: ElevationAnimationDemoFragment.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
private void setTranslationZ(
    View view, MaterialShapeDrawable materialShapeDrawable, float translationZ) {
  materialShapeDrawable.setTranslationZ(translationZ);
  ViewCompat.setTranslationZ(view, translationZ);
}