0

Sorry my bad english.

I tried to draw something on the screen with drawText(), drawRect() and drawBitmap(). WHY coordinates must be of the "float"? They should be of type "int"?

user3106572
  • 101
  • 1
  • 1
  • 3
  • You need to provide more details (and sample code) for people to answer. You should also tag the question with a language tag. – xxbbcc Jan 12 '16 at 15:42

1 Answers1

0

Here is the code:

package com.prove.provaproject_29_g;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.content.Context;
import android.graphics.*;

public class MainActivity extends ActionBarActivity
{

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(new MyView(this));
}

class MyView extends View
{
    public MyView(Context context) {
         super(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {
       super.onDraw(canvas);
       int x = getWidth();
       int y = getHeight();
       int radius;
       radius = 100;
       Paint paint = new Paint();
       paint.setStyle(Paint.Style.FILL);
       paint.setColor(Color.WHITE);
       canvas.drawPaint(paint);
       // Use Color.parseColor to define HTML colors
       paint.setColor(Color.parseColor("#CD5C5C"));
       canvas.drawCircle(x / 2, y / 2, radius, paint); // <--- coordinates of type "float"

       paint.setColor(Color.BLACK);
       paint.setTextSize(40);
       canvas.drawText("Hello", x/2, y/2, paint); // <--- coordinates of type "float"
   }
}   

}

user3106572
  • 101
  • 1
  • 1
  • 3