在circledimageview上动画背景图像



我指的是Android Wear的WatchFace示例。示例digitalwatchfaceweararableconfigactivity使用颜色选择器来更改WatchFace的背景。我想在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);
        }
    }

你可以使用下面的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);
}

相关内容

  • 没有找到相关文章

最新更新