-
Notifications
You must be signed in to change notification settings - Fork 2
/
Practice08SetTextSkewXView.java
43 lines (34 loc) · 1.17 KB
/
Practice08SetTextSkewXView.java
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
package com.geekholt.practiceui.view.lesson3;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import androidx.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
public class Practice08SetTextSkewXView extends View {
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
String text = "Hello Geekholt";
public Practice08SetTextSkewXView(Context context) {
super(context);
}
public Practice08SetTextSkewXView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public Practice08SetTextSkewXView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
{
paint.setTextSize(60);
// 使用 Paint.setTextSkewX() 来让文字倾斜
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
paint.setTextSkewX(-0.5f);
canvas.drawText(text, 100, 150, paint);
paint.setTextSkewX(0.5f);
canvas.drawText(text, 100, 230, paint);
paint.setTextSkewX(1f);
canvas.drawText(text, 100, 310, paint);
}
}