Drawing Image at the same place on different screens?


Last Updated:

  1. EightBitSpade

    EightBitSpade Member This Topic's Starter

    Joined:
    Sep 29, 2010
    Messages:
    5
    Likes Received:
    0
    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?
     

    Advertisement
  2. FoxMulder900

    FoxMulder900 Member

    Joined:
    Jun 13, 2010
    Messages:
    6
    Likes Received:
    0
    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.
     
  3. KlaymenDK

    KlaymenDK Well-Known Member

    Joined:
    May 29, 2009
    Messages:
    1,217
    Likes Received:
    130
    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.
     

Share This Page

Loading...