1、线形图设置填充色为渐变色方法:
/**
* Draws the provided path in filled mode with the provided drawable.
*
* @param c
* @param filledPath
* @param drawable
*/
protected void drawFilledPath(Canvas c, Path filledPath, Drawable drawable) {
if (clipPathSupported()) {
c.save();
c.clipPath(filledPath);
drawable.setBounds((int) mViewPortHandler.contentLeft(),
(int) mViewPortHandler.contentTop(),
(int) mViewPortHandler.contentRight(),
(int) mViewPortHandler.contentBottom());
drawable.draw(c);
c.restore();//在canvas上设置渐变色图片
} else {
throw new RuntimeException("Fill-drawables not (yet) supported below API level 18, " +
"this code was run on API level " + Utils.getSDKInt() + ".");
}
}
渐变色图片:
最终效果: