• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Drawing Image at the same place on different screens?

My question here regards drawing an image at the same place on the screen, in code, regardless of the screen size or resolution. I know that I can use dips in my layout, instead of regular pixels, to help everything be sized and placed more appropriately on different screens, but here I'm talking about doing it in code.

Say, for example, I am using a custom surface view, and in my override of its onDraw function, I'm drawing an image to the screen using canvas.drawBitmap. That function takes in two numbers for coordinates, but only in hard pixels - so the actual location of the drawn image varies depending on the screen you're viewing the app on. My question is how can I draw that image in that onDraw function so that it appears in the same relative place on every screen?
 
I am unsure if there is a better way, but I would simply get the dimensions of the screen and calculate your position based on a percentage of that.
 
That would be my approach as well; it should be possible to make a translation from DIPs or actual screen size to the pixel coordinates you need.

Good luck.
 
Back
Top Bottom