1
Drawable沒有繪製自定義TextView。任何人都可以請幫我把問題整理出來。我試圖建立的是一個顯示進度的texview。下面提到的代碼只是一個示例。CustomTextView畫布沒有繪製
public class ProgressableTextview extends TextView {
Paint mPaint;
int mProgress = 70;
int maxProgress = 100;
int mRadiud = 10;
public ProgressableTextview(Context context) {
super(context);
init();
}
public ProgressableTextview(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public ProgressableTextview(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
public void init(){
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setColor(Color.BLACK);
mPaint.setStyle(Paint.Style.FILL);
}
@Override
public void onDraw(Canvas canvas) {
canvas.drawColor(Color.GRAY);
canvas.drawRect(0, 0, (mProgress/maxProgress)*getWidth(), getMeasuredHeight(), mPaint);
canvas.save();
canvas.translate(getLeft(), 0);
super.onDraw(canvas);
canvas.restore();
}
}
我複製了你的代碼,'TextView'是可見的並且填充了灰色。有什麼問題? – eleven
是的,灰色顯示,但矩形不繪製。 – Rahul
謝謝@襪子襪子 – Rahul