我有下面的代碼在擴展的EditText我的自定義視圖:如何在View的背景上設置drawable? Android的
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int count = getLineCount();
Canvas cvs= new Canvas();
Drawable dr = this.getBackground();
Rect r = mRect;
Paint paint = mPaint;
mTextPaint.setTextSize(this.getTextSize());
Paint PaintText = mTextPaint;
for (int i = 0; i < count; i++) {
int baseline = getLineBounds(i, r);
cvs.drawText(Integer.toString(i+1), r.left, baseline + 1, PaintText);
cvs.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint);
}
cvs.drawLine(PaintText.measureText(Integer.toString(count)), this.getTop(), PaintText.measureText(Integer.toString(count)), this.getBottom(), paint);
dr.setBounds(0, 0, this.getRight(), this.getBottom());
dr.draw(cvs);
this.setBackgroundDrawable(dr);
}
爲什麼會出現什麼這種觀點的backgroind?
我很高興你解決了這個問題。 – Michael 2011-03-27 09:23:11