我想将ImageView设置为SweepGradient。将ImageView设置为PaintDrawable - Android
这里是我的尝试:
protected void onCreate(@Nullable Bundle savedInstanceState) {
ImageView colorPicker = findViewById(R.id.color_picker);
colorPicker.setImageDrawable(CreateColorPickerDrawable());
}
private PaintDrawable CreateColorPickerDrawable()
{
int[] colors = {0xFFFF0000, 0xFF00FF00, 0xFF0000FF};
PaintDrawable paintDrawable = new PaintDrawable();
paintDrawable.setCornerRadius(getResources().getDimension(R.dimen.corner_radius));
SweepGradient sweepGradient = new SweepGradient(50, 50, colors, null);
paintDrawable.getPaint().setShader(sweepGradient);
return paintDrawable;
}
但似乎没有梯度。
我也看到了这一点:Imageview set color filter to gradient
但我想我们有了是比简单的解决方案(加上它需要一个位图src和我只是想我的ImageView为矩形W /圆角角落[这可以很容易地做到/ PaintDrawable])。
如果任何人有任何指导/建议,将不胜感激!泰!
我最终希望它是动态的,硬编码的颜色只是为了测试。对不起,哥们:/ –