
大家好,
我正在尝试使用工具提示自定义 android seekbar,例如给定的图像。有没有办法在搜索栏中添加带有拇指的文本视图。或任何其他想法
谢谢
我们可以通过获得拇指的界限来做到这一点。并在 seekbar 的 progressChanged 上设置 textview 的 x
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
        boolean fromUser) {
    mDistance.setText("" + AppConstants.getDistance() + " miles");
    //Get the thumb bound and get its left value
    int x = mSeekBar.getThumb().getBounds().left;
             //set the left value to textview x value
    mDistance.setX(x);
}
    Bora(伟大的)答案的一些优化:
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
        boolean fromUser) {
    mDistance.setText("" + AppConstants.getDistance() + " miles");
    float x = seekBarX
            + mSeekBar.getThumb().getBounds().left
            - toolTipTextView.getWidth()/2
            + seekBarLayoutParams.leftMargin;
    mDistance.setX(x);
}
并声明:
private RelativeLayout.LayoutParams seekBarLayoutParams;
seekBarLayoutParams = (RelativeLayout.LayoutParams) seekbar.getLayoutParams();
//or `LinearLayout` if you're using `LinearLayout`.
private float seekBarX;
int[] location = new int[2];
seekBarX = location[0];
即使您SeekBar有边距,这也使它恰好位于拇指的中间。
但是,它不涉及Y位置。为了解决这个问题,如果你SeekBar有一个marginTop,删除它并添加marginBottom到它上面的元素(在 xml 中)。
以下计算对我有用。非常简单和合乎逻辑。
    ViewGroup.MarginLayoutParams seekBarParams = (ViewGroup.MarginLayoutParams) seekBar.getLayoutParams();
    // Calculate x position
    float x = seekBarParams.leftMargin + seekBar.getPaddingLeft() + seekBar.getThumb().getBounds().left - tvValue.getWidth()/2;
    tvValue.setX(x);
    // Calculate y position
    float y = seekBarParams.topMargin + seekBar.getPaddingTop() - tvValue.getHeight();
    tvValue.setY(y);
    已经问过了。他们为此使用 TextView,您可以使用 ImageView 或自定义 View 来满足您的目的。在这里检查。
看这个例子,你可能会从中得到想法,