【问题标题】:Fill Imageview background animation填充Imageview背景动画
【发布时间】:2016-12-16 19:58:18
【问题描述】:

如何填充图像视图背景,使其透明区域被某种颜色填充。

我想填充下面的图片 -

填充后的图像会像 -

我只想用动画从下到上填充图像的黑色区域。

请推荐一些我可以做动画的动画。

提前致谢

【问题讨论】:

  • "such that its transparent area will be filled by some color.", "i want to fill black area" 所以要填充透明或黑色区域?
  • 填充透明的暗区,原图为白色背景
  • 发布该动画的两个步骤(两张图片),因为很难弄清楚您的意思
  • 我刚刚用两张图片更新了我的问题,请检查
  • su 像这样使用可绘制对象:pastebin.com/MXvFhyVU 并使用 ObjectAnimator 将其“级别”属性从值 0 设置为 10000

标签: android animation android-animation translation


【解决方案1】:

你可以尝试在代码中添加它

ImageView backgroundImg = (ImageView) findViewById(R.id.backgroundImg);
backgroundImg.setBackgroundColor(Color.rgb(100, 100, 50));

这也将解决您的问题。只需将其添加到您的 ImageView 标记中即可。

android:background="@android:color/red"

检查这个我不确定。但是检查一下这个sn-p

您可以简单地使用自 API 11 (Honeycomb) 起可用的 ArgbEvaluator:

ValueAnimator anim = new ValueAnimator();
anim.setIntValues(color1, color2);
//anim..setIntValues(Color.parseColor("#FFFFFF"), Color.parseColor("#000000"));
anim.setEvaluator(new ArgbEvaluator());
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator valueAnimator) {
        backgroundImg.setBackgroundColor((Integer)valueAnimator.getAnimatedValue());
    }
});

anim.setDuration(300);
anim.start();

更好的是,从 API 21 (Lollipop 5.0) 开始,您可以将上面代码中的前 3 行替换为一行:

ValueAnimator anim = ValueAnimator.ofArgb(color1, color2)

【讨论】:

  • backgroundImg.setBackgroundColor(Color.parseColor("#FFFFFF"));甚至这个
  • 我想用动画来填充。
  • 颜色1和颜色2是颜色的int值
猜你喜欢
  • 2020-04-16
  • 2015-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-17
  • 1970-01-01
  • 2015-12-12
  • 1970-01-01
相关资源
最近更新 更多