Android實現控件縮放的方法有多種,下面介紹幾種常見的方法:
ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 0.5f, 1f, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(1000);
scaleAnimation.setFillAfter(true);
view.startAnimation(scaleAnimation);
ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0.5f);
ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0.5f);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.setDuration(1000);
animatorSet.playTogether(scaleX, scaleY);
animatorSet.start();
Matrix matrix = new Matrix();
matrix.postScale(0.5f, 0.5f);
view.setImageMatrix(matrix);
以上是幾種常見的實現控件縮放效果的方法,開發者可以根據具體需求選擇合適的方法來實現控件的縮放。