如何改变约束偏差?

我尝试了很多次尝试但未能解决。我想通过改变不断变化的垂直偏差来动画视图。那我怎么能打败这个呢?


ValueAnimator animator = ValueAnimator.ofInt(100, percent);

        animator.setDuration(2000);

        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            public void onAnimationUpdate(ValueAnimator animation) {

                ViewGroup.LayoutParams params = mViewTop.getLayoutParams();

                float v = ((Float.parseFloat(animation.getAnimatedValue().toString())) / 100f) -0.1f;

                if (v<0){

                    v=0;

                }

                params.verticalBias = v;

                mViewTop.setLayoutParams(params);

            }

        });

        animator.start();


慕尼黑的夜晚无繁华
浏览 76回答 1
1回答

慕村225694

你需要像下面那样改变你做错了演员需要改变ValueAnimator animator = ValueAnimator.ofInt(100, percent);&nbsp; &nbsp; &nbsp; &nbsp; animator.setDuration(2000);&nbsp; &nbsp; &nbsp; &nbsp; animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void onAnimationUpdate(ValueAnimator animation) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) mViewTop.getLayoutParams();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float v = ((Float.parseFloat(animation.getAnimatedValue().toString())) / 100f) -0.1f;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (v<0){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; v=0;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; params.verticalBias = v;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mViewTop.setLayoutParams(params);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; animator.start();
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java