Textview不遵循Seekbar Thumb

时间:2016-04-09 12:36:01

标签: android android-seekbar

我正在构建一个应用程序,其中我有一个Arc SeekBar,我正试图让TextView跟随SeekBar拇指。

我的代码:

seekBar = (ArcSeekBar)findViewById(R.id.seekArc);
        textView = (TextView)findViewById(R.id.myText);
        seekBar.setOnSeekArcChangeListener(new ArcSeekBar.OnSeekArcChangeListener() {
            @Override
            public void onProgressChanged(ArcSeekBar seekArc, int progress, boolean fromUser) {
                int x = seekBar.getmTranslateX() - seekBar.getmThumbXPos()-100;
                int y = seekBar.getmTranslateY() - seekBar.getmThumbYPos()-100;

                textView.setX(x);
                textView.setY(y);
                textView.setText(String.valueOf(progress));
            }

            @Override
            public void onStartTrackingTouch(ArcSeekBar seekArc) {

            }

            @Override
            public void onStopTrackingTouch(ArcSeekBar seekArc) {

            }
        });

我如何确保搜索栏X和Y位置。

@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        final int height = getDefaultSize(getSuggestedMinimumHeight(),
                heightMeasureSpec);
        final int width = getDefaultSize(getSuggestedMinimumWidth(),
                widthMeasureSpec);
        final int min = Math.min(width, height);
        float top = 0;
        float left = 0;
        int arcDiameter = 0;

        mTranslateX = (int) (width * 0.5f);
        mTranslateY = (int) (height * 0.5f);

        arcDiameter = min - getPaddingLeft();
        mArcRadius = arcDiameter / 2;
        top = height / 2 - (arcDiameter / 2);
        left = width / 2 - (arcDiameter / 2);
        mArcRect.set(left, top, left + arcDiameter, top + arcDiameter);

        int arcStart = (int) mProgressSweep + mStartAngle + mRotation + 90;
        mThumbXPos = (int) (mArcRadius * Math.cos(Math.toRadians(arcStart)));
        mThumbYPos = (int) (mArcRadius * Math.sin(Math.toRadians(arcStart)));

        setTouchInSide(mTouchInside);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

结果是:

enter image description here

有什么想法吗?我希望文本总是在拇指之上。

1 个答案:

答案 0 :(得分:2)

the scope of the element

你必须有中心点。 textview圆的大小必须大于其他圆

enter image description here