我正在使用MPChart Library for Android来创建图表。我想创建一个类似于下图中的图形的效果。
我想要的是让渐变快速消失而不是覆盖图形的整个高度,以达到理想的效果。
这是我设置图表背景的代码:
if (Utils.getSDKInt() >= 18) {
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.graph_gradient);
dataSet.setFillDrawable(drawable);
}
graph_gradient.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:endColor="@color/graphColorFill"
android:centerColor="@color/graphColorFillCenter"
android:startColor="@android:color/transparent" />
</shape>
颜色
<color name="graphColorFill">#1DE9B6</color>
<color name="graphColorFillCenter">#901DE9B6</color>
修改:
如果我使用@android:color / transparent作为centerColor,我会得到以下效果,因为你可以看到淡化消失在图表的左侧(因为它更低):