本文整理汇总了Java中android.graphics.drawable.ShapeDrawable.setShaderFactory方法的典型用法代码示例。如果您正苦于以下问题:Java ShapeDrawable.setShaderFactory方法的具体用法?Java ShapeDrawable.setShaderFactory怎么用?Java ShapeDrawable.setShaderFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.drawable.ShapeDrawable
的用法示例。
在下文中一共展示了ShapeDrawable.setShaderFactory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createInnerStrokesDrawable
import android.graphics.drawable.ShapeDrawable; //导入方法依赖的package包/类
private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) {
if (!mStrokeVisible) {
return new ColorDrawable(Color.TRANSPARENT);
}
ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
final int bottomStrokeColor = darkenColor(color);
final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor);
final int topStrokeColor = lightenColor(color);
final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor);
final Paint paint = shapeDrawable.getPaint();
paint.setAntiAlias(true);
paint.setStrokeWidth(strokeWidth);
paint.setStyle(Style.STROKE);
shapeDrawable.setShaderFactory(new ShaderFactory() {
@Override
public Shader resize(int width, int height) {
return new LinearGradient(width / 2, 0, width / 2, height,
new int[] { topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor },
new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f },
TileMode.CLAMP
);
}
});
return shapeDrawable;
}
示例2: createInnerStrokesDrawable
import android.graphics.drawable.ShapeDrawable; //导入方法依赖的package包/类
private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) {
if (!mStrokeVisible) {
return new ColorDrawable(Color.TRANSPARENT);
}
ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
final int bottomStrokeColor = darkenColor(color);
final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor);
final int topStrokeColor = lightenColor(color);
final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor);
final Paint paint = shapeDrawable.getPaint();
paint.setAntiAlias(true);
paint.setStrokeWidth(strokeWidth);
paint.setStyle(Style.STROKE);
shapeDrawable.setShaderFactory(new ShaderFactory() {
@Override
public Shader resize(int width, int height) {
return new LinearGradient(width / 2, 0, width / 2, height,
new int[]{topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor},
new float[]{0f, 0.2f, 0.5f, 0.8f, 1f},
TileMode.CLAMP
);
}
});
return shapeDrawable;
}
示例3: generateCircleDrawable
import android.graphics.drawable.ShapeDrawable; //导入方法依赖的package包/类
private static Drawable generateCircleDrawable(final int color) {
ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
drawable.setShaderFactory(new ShaderFactory() {
public Shader resize(int width, int height) {
return new LinearGradient(0.0f, 0.0f, 0.0f, 0.0f, color, color, TileMode.REPEAT);
}
});
return drawable;
}