用线连接两个数字

时间:2019-01-30 16:04:02

标签: java android canvas

我正在android studio中进行开发,我想用一条线连接两个数字并将这两个值求和,而剩下的结果就是中心数字的值,我该怎么做?到目前为止,这是我的代码。

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //Create a bitmap object to use as our canvas
        display = getWindowManager().getDefaultDisplay();
        size = new Point();
        display.getSize(size);
        screenWidth = size.x;
        screenHeight= size.y;
        ImageView ourFrame = (ImageView) findViewById(R.id.imageView);
        Bitmap ourBitmap = Bitmap.createBitmap(size.x, size.y, Bitmap.Config.
                ARGB_8888);
        Canvas ourCanvas = new Canvas(ourBitmap);
        //A paint object that does our drawing, on our canvas
        Paint paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(4);
        Paint centralNumber = new Paint();
        centralNumber.setTextSize(60);
        int RandomCentralNumber = new Random().nextInt(400) +60;
        int Randomnumber1 = new Random().nextInt(100)+20;
        int Randomnumber2 = new Random().nextInt(100)+20;
        String CentralNumber = Integer.toString(RandomCentralNumber);

        //Set the background color
        ourCanvas.drawColor(Color.WHITE);

        paint.setColor(Color.BLACK);
//Now draw a load of stuff on our canvas
        ourCanvas.drawCircle(size.x/2, size.y/2, 170, paint);
        ourCanvas.drawText(CentralNumber,size.x/2,size.y/2,centralNumber);
        ourCanvas.drawText(String.valueOf(Randomnumber1),500,300,centralNumber);
        ourCanvas.drawText(String.valueOf(Randomnumber2),700,1040,centralNumber);
        //Now put the canvas in the frame
        ourFrame.setImageBitmap(ourBitmap);

This is what I want to do, connect both numbers with a line and sum them.

0 个答案:

没有答案