我已經設法創建繪畫,創建一個非常漂亮的平滑筆劃圍繞文本。但是我在繪製到需要的地方時遇到了麻煩,主要是我相信擴展視圖而不是TextView的事實?Android - 筆觸文字,延伸textview/view
我的目標是能夠圍繞我想要的佈局上的任何文本進行筆劃。
DrawView.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,我無法讓它工作!
對不起,如果它令人困惑,我知道我必須離開軌道,但一直在努力幾個小時,找不到更清楚的話!
完美!謝謝! – Jonno