1

So, I want to make something like this: from my online database I get x,y coordinates, height and width of the object, image for my object. I want to make custom view so I can place all those objects to right places so that those objects are same on all the screen sizes. My question is how to do this? Do i need to create layout xml file or not? What iv got so far is that I need to extend my object with View, use onMeasure and onDraw methods, but how?

Miljan Vulovic
  • 1,322
  • 2
  • 12
  • 42

1 Answers1

0

I would not create that with x,y coordinates because of all these different screen sizes, I would use percents of screen to be sure that it looks the same on all screens (or at least, not totally different).

Then, you just have to extend the View class and it should be enough.

I would refer to this cool tutorial to get the things properly done (it is very easy to implement these things not properly and you'll run in big trouble when you'll want to make it a bit more complex). Android Doc

Laurent Meyer
  • 2,596
  • 3
  • 28
  • 53
  • Thank you for this, what I dont understand, do I use constructor with attribute set or without it, what sizes do I need to send to my object so it would look everywhere same? – Miljan Vulovic Jun 06 '15 at 22:59
  • 1) http://stackoverflow.com/a/10863649/2545832 (pretty straightforward) 2) I would send something like x=0.5 y =0.5 w=0.5 h=0.5 to have a square filling the right bottom corner of the screen (hope you get the idea: the x and y are defining the top left point of the rectangle) – Laurent Meyer Jun 06 '15 at 23:04