我已经设法创建了在文本周围创建非常平滑的笔触的油漆。但是我无法让它吸引到我需要的地方,主要是我相信我正在扩展 View 而不是 TextView?
我的目标是能够围绕我想要的布局上的任何文本进行描边。
绘图视图.java
public class DrawView extends View{
Paint paint = new Paint();
String text = "Blank";
public DrawView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public DrawView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public DrawView(Context context) {
super(context);
}
public void setText(String text) {
this.text = text;
}
public String getText() {
return text;
}
public void draw(Canvas canvas ) {
Paint strokePaint = new Paint();
strokePaint.setARGB(255, 0, 0, 0);
strokePaint.setTextSize(28);
//strokePaint.setTypeface(tf);
strokePaint.setStyle(Paint.Style.STROKE);
strokePaint.setStrokeJoin(Paint.Join.ROUND);
strokePaint.setStrokeCap(Paint.Cap.ROUND);
strokePaint.setStrokeWidth(9);
strokePaint.setAntiAlias(true);
Paint textPaint = new Paint();
textPaint.setARGB(255, 255, 255, 255);
textPaint.setTextSize(28);
//textPaint.setTypeface(tf);
textPaint.setAntiAlias(true);
canvas.drawText(text, 99, 99, strokePaint);
canvas.drawText(text, 99, 101, strokePaint);
canvas.drawText(text, 101, 99, strokePaint);
canvas.drawText(text, 101, 101, strokePaint);
canvas.drawText(text, 100, 100, textPaint);
super.draw(canvas);
}
}
xml
<com.shadow.pets.DrawView
android:id="@+id/energyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
这个视图覆盖了我的整个 LinearLayout 并且我无法控制它在哪里绘制?如果我扩展 TextView,我根本无法让它工作!
对不起,如果它令人困惑,我知道我一定是偏离了轨道,但已经尝试了几个小时,找不到更清楚的话!