numan salati
numan salati

Reputation: 19494

How to animate a view's background in android

I am targeting level 11+

Its easy to to animate the alpha of the entire view by doing something like

view.animate().alpha(0)

But this fades the entire view.

I am interested in fading just the background resource/drawable of a view.

How would I do that?

For now I am doing this:

view.getBackground().setAlpha(0)  

But this obviously doesn't animate (fade out) it.

Upvotes: 0

Views: 2186

Answers (2)

Mario
Mario

Reputation: 758

you could use nine old androids (https://github.com/JakeWharton/NineOldAndroids)

    ValueAnimator colorAnim = ObjectAnimator.ofInt(this, "backgroundColor", /*Red*/0xFFFF8080, /*Blue*/0xFF8080FF);
colorAnim.setDuration(3000);
colorAnim.setEvaluator(new ArgbEvaluator());
colorAnim.setRepeatCount(ValueAnimator.INFINITE);
colorAnim.setRepeatMode(ValueAnimator.REVERSE);
colorAnim.start();

Upvotes: 1

Stefano Mondino
Stefano Mondino

Reputation: 1219

you could transform your view in a relative layout and set two separate views inside of it, one for the background (with alpha animation) and one for contents

Upvotes: 0

Related Questions