在circledimageview上制作动画背景图像

时间:2015-07-27 15:32:01

标签: android-view wear-os

我指的是适用于Android Wear的WatchFace示例。 DigitialWatchFaceWearableConfigActivity示例使用颜色选择器来更改Watch Face背景。我想在circledimageview上使用图像背景。发生的情况是图像在中心和非中心位置保持相同的大小,只有黑色圆圈改变大小。我需要在onCenterPosition和onNonCenterPosition中实现什么才能缩小和增大背景图像?

    @Override
    public void onCenterPosition(boolean animate) {

        if (animate) {
            mShrinkAnimator.cancel();
            if (!mExpandAnimator.isRunning()) {
                mExpandCircleAnimator.setFloatValues(mColor.getCircleRadius(), mExpandCircleRadius);
                mExpandLabelAnimator.setFloatValues(mLabel.getAlpha(), EXPAND_LABEL_ALPHA);
                mExpandAnimator.start();
            }
        } else {
            mExpandAnimator.cancel();
            mColor.setCircleRadius(mExpandCircleRadius);
            mLabel.setAlpha(EXPAND_LABEL_ALPHA);
        }
    }

    @Override
    public void onNonCenterPosition(boolean animate) {

        if (animate) {
            mExpandAnimator.cancel();
            if (!mShrinkAnimator.isRunning()) {
                mShrinkCircleAnimator.setFloatValues(mColor.getCircleRadius(), mShrinkCircleRadius);
                mShrinkLabelAnimator.setFloatValues(mLabel.getAlpha(), SHRINK_LABEL_ALPHA);
                mShrinkAnimator.start();
            }
        } else {
            mShrinkAnimator.cancel();
            mColor.setCircleRadius(mShrinkCircleRadius);
            mLabel.setAlpha(SHRINK_LABEL_ALPHA);
        }
    }

1 个答案:

答案 0 :(得分:0)

您可以使用以下简单的ScaleX和ScaleY代码来操作onCenterPosition和onNonCenterPosition的背景,

@Override
public void onCenterPosition(boolean b) {
    image.setAlpha(1f);
    image.setBackgroundResource(R.drawable.blue_oval); // This one is needed if you want to change background on center position
    image.setScaleX(1.0f);
    image.setScaleY(1.0f);
    text.setScaleY(1.0f);
    text.setAlpha(1f);

}

@Override
public void onNonCenterPosition(boolean b) {
    image.setAlpha(0.5f);
    image.setBackgroundResource(R.drawable.gray_oval); // This one is needed if you want to change background on non center position
    image.setScaleX(0.8f);
    image.setScaleY(0.8f);
    text.setScaleY(0.8f);

    text.setAlpha(0.5f);
}