Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, answering my own question - here is the way I resolved the issue:</p> <ol> <li>I placed the background image on the top of my <code>ImageView</code> with <code>ImageView.setScaleType(ScaleType.FIT_START)</code></li> <li>I calculated the scale factor of my background image like so:</li> </ol> <pre> WindowManager mgr = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); DisplayMetrics metrics = new DisplayMetrics(); mgr.getDefaultDisplay().getMetrics(metrics); Drawable image = context.getResources().getDrawable(R.drawables.someImage); float scale = metrics.widthPixels / (float) image.getIntrinsicWidth(); </pre> <ol> <li>Finally, I used this scale in a custom ImageView class that loads the overlays to position and scale the view properly:</li> </ol> <pre> public class OverlayImage extends ImageView { private int imgWidth, imgHeight; private final float scale; public OverlayImage(Context context, int xPos, int yPos, float scale) { super(context); this.scale = scale; LayoutParams animParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); animParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); animParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); animParams.leftMargin = (int) (scale * xPos); animParams.topMargin = (int) (scale * yPos); setLayoutParams(animParams); Drawable dr = context.getResources().getDrawable(R.id.someImage); setBackgroundDrawable(dr); imgWidth = dr.getIntrinsicWidth(); imgHeight = dr.getIntrinsicHeight(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension((int) (scale * imgWidth), (int) (scale * imgHeight)); } } </pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload