android:你如何使用搜索栏缩放圆圈?

时间:2012-01-23 06:34:30

标签: android scale draw geometry seekbar

我已经通过编程方式绘制了一个圆圈来充当画笔,但我在缩放它时遇到了麻烦。我已经将半径值连接到了搜索栏方法的进度,并且它们以数字方式缩放,但是当我触摸我的平板电脑时,画笔的大小仍然相同。当我滑动搜索条时,如何让画笔不断缩放?

1 个答案:

答案 0 :(得分:0)

以下是在搜索栏进度中更改圆的半径的代码

private class test extends View {
    private int radius;

    public test(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setAntiAlias(false);
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(Color.RED);

        // RectF rect = new RectF(100, 100, 200, 200);
        // canvas.drawRect(rect, paint);
        canvas.drawCircle(50, 50, getRadius(), paint);
        canvas.drawLine(10, 10, 10, 10 + 15, paint);

    }

    /**
     * @param radius the radius to set
     */
    public void setRadius(int radius) {
        this.radius = radius;
    }

    /**
     * @return the radius
     */
    public int getRadius() {
        return radius;
    }
}

在您的活动中

LinearLayout layout = new LinearLayout(this);
    layout.setLayoutParams(new LayoutParams(320, 420));
    layout.setOrientation(LinearLayout.VERTICAL);
    tt = new test(this);
    tt.setLayoutParams(new LayoutParams(100, 200));
    layout.addView(tt);

    SeekBar bar = new SeekBar(this);
    bar.setMax(40);
    bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
            // TODO Auto-generated method stub
            tt.setRadius(progress);
            tt.invalidate();
        }
    });

    layout.addView(bar);

    setContentView(layout);

希望对你有用。