下面列出了android.graphics.Paint#DITHER_FLAG 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void init(Context context) {
mContext = context;
DisplayMetrics dm = getResources().getDisplayMetrics();
mScreenW = dm.widthPixels;
mHeadBmp = BitmapFactory.decodeResource(getResources(), R.drawable.load_more_1);
// mScrDistance = mScreenH / 3 - 46;
mHeadW = mHeadBmp.getWidth();
mHeadH = mHeadBmp.getHeight();
mInitLeftPX = mScreenW / 2 - mHeadW;
mInitRightPX = mScreenW / 2 + mHeadW;
mBmpL = mScreenW / 2 - mHeadBmp.getWidth() / 2;
mBmpT = 0;
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
mPaint.setColor(Color.RED);
mPaint.setStyle(Style.FILL);//设置非填充
mScroller = new Scroller(mContext, new DecelerateInterpolator());
mScroller1 = new Scroller(mContext, new DecelerateInterpolator());
mAniDraw = (AnimationDrawable) mAnimList.getDrawable();
}
public DataRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) {
super(viewPortHandler);
this.mAnimator = animator;
mRenderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mRenderPaint.setStyle(Style.FILL);
mDrawPaint = new Paint(Paint.DITHER_FLAG);
mValuePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mValuePaint.setColor(Color.rgb(63, 63, 63));
mValuePaint.setTextAlign(Align.CENTER);
mValuePaint.setTextSize(Utils.convertDpToPixel(9f));
mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mHighlightPaint.setStyle(Paint.Style.STROKE);
mHighlightPaint.setStrokeWidth(2f);
mHighlightPaint.setColor(Color.rgb(255, 187, 115));
}
private void setupDrawing() {
brushSize = getResources().getInteger(R.integer.medium_size);
lastBrushSize = brushSize;
drawPath = new Path();
drawPaint = new Paint();
drawPaint.setColor(paintColor);
drawPaint.setAntiAlias(true);
drawPaint.setStrokeWidth(brushSize);
drawPaint.setStyle(Paint.Style.STROKE);
drawPaint.setStrokeJoin(Paint.Join.ROUND);
drawPaint.setStrokeCap(Paint.Cap.ROUND);
drawPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
canvasPaint = new Paint(Paint.DITHER_FLAG);
}
public CardViewDecoration(Resources resources, int backgroundColor, float radius) {
mShadowStartColor = resources.getColor(R.color.cardview_shadow_start_color);
mShadowEndColor = resources.getColor(R.color.cardview_shadow_end_color);
mShadowSize = resources.getDimension(R.dimen.cardview_shadow_size) * SHADOW_MULTIPLIER;
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
mPaint.setColor(backgroundColor);
mCornerShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
mCornerShadowPaint.setStyle(Paint.Style.FILL);
mCornerShadowPaint.setDither(true);
mCornerRadius = radius;
mPreShadowBounds = new RectF();
mEdgeShadowPaint = new Paint(mCornerShadowPaint);
buildShadowCorners();
}
private void init(Context context) {
mBitmapPaint = new Paint(Paint.DITHER_FLAG | Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
mBgColor = ResourcesUtils.getAttrColor(context, R.attr.colorPure);
mColor = ResourcesUtils.getAttrColor(context, R.attr.colorPureInverse);
mWidth = LayoutUtils.dp2pix(context, 4);
mPath = new Path();
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mRecycler = new Recycler();
}
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
if (source == null) return null;
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
// TODO this could be acquired from the pool too
Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(result);
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG | Paint
.ANTI_ALIAS_FLAG);
paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader
.TileMode.CLAMP));
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
return result;
}
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
if (source == null) return null;
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
// TODO this could be acquired from the pool too
Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(result);
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG | Paint
.ANTI_ALIAS_FLAG);
paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader
.TileMode.CLAMP));
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
return result;
}
public CustomShadow(Resources resources, int backgroundColor, float radius, float shadowSize,
float maxShadowSize) {
mShadowStartColor = resources.getColor(R.color.cardview_shadow_start_color);
mShadowEndColor = resources.getColor(R.color.cardview_shadow_end_color);
mInsetShadow = resources.getDimensionPixelSize(R.dimen.cardview_compat_inset_shadow);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
mPaint.setColor(backgroundColor);
mCornerShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
mCornerShadowPaint.setStyle(Paint.Style.FILL);
mCornerRadius = (int) (radius + .5f);
mCardBounds = new RectF();
mEdgeShadowPaint = new Paint(mCornerShadowPaint);
mEdgeShadowPaint.setAntiAlias(false);
setShadowSize(shadowSize, maxShadowSize);
CustomShadow.sRoundRectHelper = new RoundRectHelper() {
@Override
public void drawRoundRect(Canvas canvas, RectF bounds, float cornerRadius, Paint paint) {
canvas.drawRoundRect(bounds, cornerRadius, cornerRadius, paint);
}
};
}
/**
* Inits paint objects and default values.
*/
private void initView() {
starPath = new Path();
cornerPathEffect = new CornerPathEffect(starCornerRadius);
paintStarOutline = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
paintStarOutline.setStyle(Paint.Style.FILL_AND_STROKE);
paintStarOutline.setAntiAlias(true);
paintStarOutline.setDither(true);
paintStarOutline.setStrokeJoin(Paint.Join.ROUND);
paintStarOutline.setStrokeCap(Paint.Cap.ROUND);
paintStarOutline.setColor(Color.BLACK);
paintStarOutline.setPathEffect(cornerPathEffect);
paintStarBorder = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
paintStarBorder.setStyle(Paint.Style.STROKE);
paintStarBorder.setStrokeJoin(Paint.Join.ROUND);
paintStarBorder.setStrokeCap(Paint.Cap.ROUND);
paintStarBorder.setStrokeWidth(starBorderWidth);
paintStarBorder.setPathEffect(cornerPathEffect);
paintStarBackground = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
paintStarBackground.setStyle(Paint.Style.FILL_AND_STROKE);
paintStarBackground.setAntiAlias(true);
paintStarBackground.setDither(true);
paintStarBackground.setStrokeJoin(Paint.Join.ROUND);
paintStarBackground.setStrokeCap(Paint.Cap.ROUND);
paintStarFill = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
paintStarFill.setStyle(Paint.Style.FILL_AND_STROKE);
paintStarFill.setAntiAlias(true);
paintStarFill.setDither(true);
paintStarFill.setStrokeJoin(Paint.Join.ROUND);
paintStarFill.setStrokeCap(Paint.Cap.ROUND);
defaultStarSize = applyDimension(COMPLEX_UNIT_DIP, 30, getResources().getDisplayMetrics());
}
public BubbleLayout(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
setLayerType(LAYER_TYPE_SOFTWARE, null);
setWillNotDraw(false);
initAttr(context.obtainStyledAttributes(attrs, R.styleable.BubbleLayout, defStyleAttr, 0));
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
mPaint.setStyle(Paint.Style.FILL);
mPath = new Path();
initPadding();
}
public RoundRectDrawable(int backgroundColor, float radius) {
mRadius = radius;
// increment it to account for half pixels.
if (mHasJellybeanMr1 && mRadius >= 1f)
mRadius += .5f;
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
mPaint.setColor(backgroundColor);
mCornerRect = new RectF();
mBoundsF = new RectF();
mBoundsI = new Rect();
}
public RoundRectDrawableWithShadow(Resources resources, int backgroundColor, float size) {
float density = ResourceUtils.obtainDensity(resources);
insetShadow = (int) (1f * density + 0.5f);
paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
paint.setColor(backgroundColor);
cornerShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
cornerShadowPaint.setStyle(Paint.Style.FILL);
cornerRadius = (int) (size + .5f);
cardBounds = new RectF();
edgeShadowPaint = new Paint(cornerShadowPaint);
edgeShadowPaint.setAntiAlias(false);
setShadowSize(size, size);
}
public ShadowRenderer(int color) {
shadowPaint = new Paint();
setShadowColor(color);
transparentPaint.setColor(Color.TRANSPARENT);
cornerShadowPaint = new Paint(Paint.DITHER_FLAG);
cornerShadowPaint.setStyle(Paint.Style.FILL);
edgeShadowPaint = new Paint(cornerShadowPaint);
}
public RoundRectDrawable(int backgroundColor, float radius) {
mRadius = radius;
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
mPaint.setColor(backgroundColor);
mBoundsF = new RectF();
mBoundsI = new Rect();
}
private void init(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DividerView);
int color = a.getColor(R.styleable.DividerView_dividerColor, Color.BLACK);
mDividerWidth = a.getDimensionPixelOffset(R.styleable.DividerView_dividerWidth, 0);
mDividerHeight = a.getDimensionPixelOffset(R.styleable.DividerView_dividerHeight, 0);
a.recycle();
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
mPaint.setColor(color);
mRect = new Rect();
}
private void setupStrokePaint(int color, int borderWidth) {
strokePaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
strokePaint.setStrokeJoin(Paint.Join.ROUND);
strokePaint.setStrokeCap(Paint.Cap.ROUND);
strokePaint.setStyle(Paint.Style.STROKE);
strokePaint.setColor(color);
strokePaint.setStrokeWidth(borderWidth);
}
public WheelPicker(Context context, AttributeSet attrs) {
super(context, attrs);
adapter = new Adapter();
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.WheelPicker);
mItemTextSize = a.getDimensionPixelSize(R.styleable.WheelPicker_scroll_item_text_size,
getResources().getDimensionPixelSize(R.dimen.WheelItemTextSize));
mVisibleItemCount = a.getInt(R.styleable.WheelPicker_scroll_visible_item_count, 7);
selectedItemPosition = a.getInt(R.styleable.WheelPicker_scroll_selected_item_position, 0);
textMaxWidthPosition = a.getInt(R.styleable.WheelPicker_scroll_maximum_width_text_position, -1);
maxWidthText = a.getString(R.styleable.WheelPicker_scroll_maximum_width_text);
mSelectedItemTextColor = a.getColor(R.styleable.WheelPicker_scroll_selected_item_text_color, -1);
mItemTextColor = a.getColor(R.styleable.WheelPicker_scroll_item_text_color, 0xFF424242);
backgroundColor = a.getColor(R.styleable.WheelPicker_scroll_background_color, 0xFFF5F5F5);
backgroundOfSelectedItem = a.getColor(R.styleable.WheelPicker_scroll_selected_item_background, 0xFFFFFFFF);
mItemSpace = a.getDimensionPixelSize(R.styleable.WheelPicker_scroll_item_space,
getResources().getDimensionPixelSize(R.dimen.WheelItemSpace));
hasIndicator = a.getBoolean(R.styleable.WheelPicker_scroll_indicator, false);
mIndicatorColor = a.getColor(R.styleable.WheelPicker_scroll_indicator_color, 0xFFDDDDDD);
mIndicatorSize = a.getDimensionPixelSize(R.styleable.WheelPicker_scroll_indicator_size,
getResources().getDimensionPixelSize(R.dimen.WheelIndicatorSize));
hasAtmospheric = a.getBoolean(R.styleable.WheelPicker_scroll_atmospheric, false);
mItemAlign = a.getInt(R.styleable.WheelPicker_scroll_item_align, ALIGN_CENTER);
a.recycle();
updateVisibleItemCount();
paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG | Paint.LINEAR_TEXT_FLAG);
paintBackground = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG );
paint.setTextSize(mItemTextSize);
updateItemTextAlign();
computeTextSize();
scroller = new Scroller(getContext());
ViewConfiguration conf = ViewConfiguration.get(getContext());
minimumVelocity = conf.getScaledMinimumFlingVelocity();
maximumVelocity = conf.getScaledMaximumFlingVelocity();
touchSlop = conf.getScaledTouchSlop();
rectDrawn = new Rect();
rectIndicatorHead = new Rect();
rectIndicatorFoot = new Rect();
rectCurrentItem = new Rect();
}
public TriangleDrawable(int color) {
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
mPaint.setColor(color);
mPath = new Path();
}
public DebugCanvasLogger() {
paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG | Paint.FILTER_BITMAP_FLAG);
paint.setTextSize(25.0f);
}
public PolygonDrawable(int num, int color) {
mNum = num;
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(color);
}