pic:
如何自定义特定的搜索栏,如图片?
我认为重点是:
当手指在搜索栏上移动时,如何呈现显示进度的暂停视图。
有些视图哪个层与搜索栏的父视图相同,这些视图在搜索栏附近,这些视图是否会与暂停视图重叠?
答案 0 :(得分:0)
看一下这个答案:13887556
这可能是一个很好的起点。 尝试扩展SeekBar并覆盖onMeasure()和onDraw方法():
@Override
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (labelBackground != null)
{
viewWidth = getMeasuredWidth();
barHeight = getMeasuredHeight();// returns only the bar height (without the label);
setMeasuredDimension(viewWidth, barHeight + labelBackground.getHeight());
}
}
@Override
protected synchronized void onDraw(Canvas canvas)
{
if (labelBackground != null)
{
barBounds.left = getPaddingLeft();
barBounds.top = labelBackground.getHeight() + getPaddingTop();
barBounds.right = barBounds.left + viewWidth - getPaddingRight() - getPaddingLeft();
barBounds.bottom = barBounds.top + barHeight - getPaddingBottom() - getPaddingTop();
progressPosX = barBounds.left + ((float) this.getProgress() / (float) this.getMax()) * barBounds.width();
labelPos.x = (int) progressPosX - labelOffset;
labelPos.y = getPaddingTop();
progressDrawable = getProgressDrawable();
progressDrawable.setBounds(barBounds.left, barBounds.top, barBounds.right, barBounds.bottom);
progressDrawable.draw(canvas);
labelTextPaint.getTextBounds(labelText, 0, labelText.length(), labelTextRect);
canvas.drawBitmap(labelBackground, labelPos.x, labelPos.y, labelBackgroundPaint);
canvas.drawText(labelText, labelPos.x + labelBackground.getWidth() / 2 - labelTextRect.width() / 2, labelPos.y + labelBackground.getHeight() / 2 + labelTextRect.height() / 2, labelTextPaint);
thumbX = (int) progressPosX - getThumbOffset();
thumbDrawable.setBounds(thumbX, barBounds.top, thumbX + thumbDrawable.getIntrinsicWidth(), barBounds.top + thumbDrawable.getIntrinsicHeight());
thumbDrawable.draw(canvas);
} else
{
super.onDraw(canvas);
}