I am trying to figure out how to fill background color of a card from bottom to top based on the processing of a particular task. I want the background color of card to be filled slowly from bottom to top approach based on some timer or processing. How to achieve this scenario. Please help me here.
Asked
Active
Viewed 758 times
1
-
http://stackoverflow.com/questions/2614545/animate-change-of-view-background-color-in-android – Randyka Yudhistira Dec 27 '16 at 07:33
-
@Randyka i need to fill background color of cardview percentage wise based on task this is the animation which will immediately change the color. I need something like this https://github.com/fanrunqi/WaveProgressView. Pls have look and suggest – Dec 27 '16 at 07:38
1 Answers
0
You can easily achieve this with Clipping. This is a modified code from Android Drawable Resources.
First specify the clipping view in XML file saved at res/drawable/clip.xml
<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/android"
android:clipOrientation="vertical"
android:gravity="bottom" />
It basically means that whatever drawable you assign to this xml, it will be clipped vertically starting from the bottom. Then in your cardview XML set this drawable as a background.
<CardView
android:id="@+id/cardview"
android:background="@drawable/clip"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
Then in your activity do something like this
CardView cardview = (CardView) findViewById(R.id.cardview);
ClipDrawable drawable = (ClipDrawable) cardview.getBackground();
drawable.setLevel(/*your level*/);
Regarding the level:
Increasing the level reduces the amount of clipping and slowly reveals the image.The default level is 0, which is fully clipped so the image is not visible. When the level is 10,000, the image is not clipped and completely visible. Hope this helps.

Arnis Shaykh
- 544
- 5
- 21