我正在尝试在Android中构建自定义搜索栏。我所做的就像是
我想要在搜索栏下方显示进度,如
这是我的代码
protected synchronized void onDraw(Canvas canvas) {
try {
super.onDraw(canvas);
mText = String.valueOf(getProgress());
mTextWidth = mPaint.measureText(mText);
Rect bounds = this.getProgressDrawable().getBounds();
float xImg = bounds.width() * getProgress() / getMax() + imagepaddingleft + oldPaddingLeft;
float yImg = imagepaddingtop + oldPaddingTop;
float xText = bounds.width() * getProgress() / getMax() + mImgWidth / 2 - mTextWidth / 2 + textpaddingleft + oldPaddingLeft;
float yText = yImg + textpaddingtop + mImgHei / 2 + getTextHei() / 4;
canvas.drawBitmap(bm, xImg, yImg, mPaint);
canvas.drawText(mText, xText, yText, mPaint);
} catch (Exception e) {
e.printStackTrace();
}
}
任何帮助将不胜感激。
答案 0 :(得分:0)
请从以下链接下载样本并根据需要进行修改