-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaintShadowLayerView.java
More file actions
61 lines (52 loc) · 2.15 KB
/
PaintShadowLayerView.java
File metadata and controls
61 lines (52 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.work.basic;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
/**
* Title: LineShadowView
* <p>
* Description:阴影效果分割线
* </p>
*
* @author Changbao
* @date 2018/12/14 17:22
*/
public class PaintShadowLayerView extends View {
public PaintShadowLayerView(Context context) {
super(context);
}
public PaintShadowLayerView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public PaintShadowLayerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
setLayerType(LAYER_TYPE_SOFTWARE, null);//对单独的View在运行时阶段禁用硬件加速
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.RED);
paint.setStrokeWidth(5);
/*
setShadowLayer 在之后的绘制内容下面加一层阴影。
构造器中, radius 是阴影的模糊范围; dx dy 是阴影的偏移量; shadowColor 是阴影的颜色。
如果要清除阴影层,使用 clearShadowLayer() 。
注意:
在硬件加速开启的情况下, setShadowLayer() 只支持文字的绘制,文字之外的绘制必须关闭硬件加速才能正常绘制阴影。
如果 shadowColor 是半透明的,阴影的透明度就使用 shadowColor 自己的透明度;
而如果 shadowColor 是不透明的,阴影的透明度就使用 paint 的透明度。
*/
paint.setShadowLayer(5F, 25F, 30F, Color.GREEN);
//paintDash.clearShadowLayer();
canvas.drawLine(0, 0, getMeasuredWidth() - getPaddingLeft() - getPaddingRight()
, getMeasuredHeight() - getPaddingTop() - getPaddingBottom(), paint);
paint.setTextSize(20);
canvas.drawText("Paint.setShadowLayer", 100, 100, paint);
canvas.drawCircle(150, 150, 50, paint);
}
}