0
我應該怎麼做來定製特定的搜索條,如PIC?
我想的一點是:
當手指在搜索條,如何呈現顯示進度懸浮視圖移動。
有一些視圖哪個圖層與seekbar的父視圖具有相同的級別,這些視圖在seekbar附近,這些視圖是否會與暫停視圖重疊?
我應該怎麼做來定製特定的搜索條,如PIC?
我想的一點是:
當手指在搜索條,如何呈現顯示進度懸浮視圖移動。
有一些視圖哪個圖層與seekbar的父視圖具有相同的級別,這些視圖在seekbar附近,這些視圖是否會與暫停視圖重疊?
這個答案請看:13887556
這可能是一個很好的起點。 儘可能擴大搜索欄和覆蓋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);
}
檢查Android SDK中,有例如與seekbars :)最好的辦法:在Eclipse中,我們按新>新的Android示例項目>你把API演示>你創建項目>然後你在你的手機上運行它:)然後你去研究它。如果你找到它,你可以去你的eclipse代碼資源,並搜索它可以比較代碼與手機中的應用:) – deadfish
感謝您的advise.I搜索了一些信息,並知道如何自定義一個正常的seekbar。但是,這一個我不知道如何解決。 – Vince