【发布时间】:2012-06-09 17:06:25
【问题描述】:
我在使用可绘制对象的setShaderFactory() 方法填充包含自定义PathShape 的ShapeDrawable 时遇到问题。以下代码在绘制RectShape 时完美运行:
ShapeDrawable shape = new ShapeDrawable();
shape.setShape(new RectShape());
shape.setShaderFactory(new ShaderFactory() {
@Override
public Shader resize(int width, int height) {
LinearGradient gradient = new LinearGradient (0, 0,
width, height, Color.Red, Color.Blue,
TileMode.REPEAT);
return gradient;
}
});
当我将RectShape 更改为任何自定义PathShape 时,drawable 仅使用渐变起始颜色(红色)填充整个形状。换句话说,自定义形状绘制正确,但颜色完全错误。有没有人见过这个并且知道可能是什么问题?
【问题讨论】: