Drawing Image at the same place on different screens?

Discussion in 'Application Development' started by EightBitSpade, Oct 7, 2010.

  1. EightBitSpade

    EightBitSpade Member
    5

    Sep 29, 2010
    5
    0
    5
    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
    5

    Jun 13, 2010
    6
    0
    5
    Software Developer
    Portsmouth, OH
    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
    143

    May 29, 2009
    1,217
    130
    143
    Denmark
    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...