1

I'm trying to learn about drawing on the Android canvas. This code seems valid and compiles, but I don't get my shape.

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ShapeDrawable shape = new ShapeDrawable(new ArcShape(0, 250));
        shape.setIntrinsicHeight(100);
        shape.setIntrinsicWidth(100);
        shape.getPaint().setColor(Color.RED);
        Canvas canvas = new Canvas();
        shape.draw(canvas);

    }
}

I'm trying to follow the tutorial here: http://kirill-poletaev.blogspot.com/2013/02/android-beginner-tutorial-part-90-path.html

Kara
  • 6,115
  • 16
  • 50
  • 57
c_idle
  • 1,448
  • 4
  • 22
  • 40
  • https://github.com/Korilakkuma/CanvasView/blob/master/com/example/canvas/CanvasView.java use this link – Yogendra Feb 01 '15 at 14:43
  • http://stackoverflow.com/questions/11328848/drawing-a-circle-where-the-user-has-touched-on-canvas/28263820#28263820 – Yogendra Feb 01 '15 at 14:44

1 Answers1

1

ShapeDrawable object is a Drawable you can set to a view background for instance. You could do something like this.-

ImageView yourImage = (ImageView) findViewById(R.id.yourImageId);
yourImage.setImageDrawable(shape);
ssantos
  • 16,001
  • 7
  • 50
  • 70
  • Yeah, that worked. Do you know how I would be able to get this for an TextView background so that my shape grows and shrinks with the content? – c_idle Oct 14 '13 at 21:23
  • Mmh as far as I know, is the `TextView` itself which wraps to its background size. You could, however, put an ImageView (your custom draw) and the TextView inside a `RelativeLayout`, align the `ImageView` top,right,bottom,left the `TextView`, and play with `scaleType` attr till you're happy with the results. – ssantos Oct 14 '13 at 21:32
  • @ssantos Asking for upvotes is considered bad manners on StackOverflow. Accepted answers, fine. But asking for upvotes looks like rep farming. Answers shoudl be upvoted when they are particularly insightful, especially useful, unique, show a lot of effort etc. You should leave it to the community to decide if answers should be voted up. – Simon Oct 14 '13 at 21:42
  • Well, actually meaning upvote *or* accepting (just in case an answer is not exactly right, but useful). Anyway, I get your point, my bad. – ssantos Oct 14 '13 at 21:45