2

I need to place an image dynamically at runtime on another Image precisely at x,y of the background Image.

I have the following details:

Overlay Image Attributes(Red): x = 58, y =232, h=266, w=431
Background Image(Black): match_parent, w=1024,h=768

Here x,y is the top left corner of the overlay.

Note: The x,y of the Overlay image is with respect to the background image and not the entire screen layout. The background image might get stretched when the ActionBar is hidden. The layout_width and layout_height of the background image is set to match_parent. and the scaleType is "center".

with the below code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    RelativeLayout root = (RelativeLayout) findViewById(R.id.rootlayout);

    backIV = (ImageView) findViewById(R.id.imageView1);

    Content = new ImageView(this);
    Content.setImageDrawable(getResources().getDrawable(R.drawable.content_1));
    params = new RelativeLayout.LayoutParams(431, 266);

    rl.addView(Content, params);

    root.addView(rl);


}

From the code above:

From the Above code

[What i want]

What i want

From many solutions and suggestions on SO, none worked for me. Believe me, am not posting this question without trying anything.

SKK
  • 5,261
  • 3
  • 27
  • 39

1 Answers1

1

see my answer for this question: How to maintain multi layers of ImageViews and keep their aspect ratio based on the largest one?

this is an extended ImageView that supports multiple Drawable layers

Community
  • 1
  • 1
pskink
  • 23,874
  • 6
  • 66
  • 77
  • Works exactly how i wanted. Thanks a lot. :) I just have to modify my layout to have LayeredImageView instead of ImageView now. – SKK Jul 16 '13 at 09:51
  • Hey, I need OnCLickListeners on the overlayed Images. how to do it. please give inputs. – SKK Jul 16 '13 at 11:13
  • I am not able to figure out how to achieve it. Could you please give me some explanation on code about how i can set onclickListeners for the overlayed image drawables. there will be multiple overlays. and what i need is something like you clicked on Image 1, Image 2 and so on. – SKK Jul 17 '13 at 07:42
  • i didn't try yet but i think you should call matrix.mapRect two times and then check if the point is inside – pskink Jul 17 '13 at 09:18
  • I am using the Touch points(event.getX(),event.getY()). using that am checking which Image overlay is being touched. based on that i am performing the operation i need. – SKK Jul 17 '13 at 09:35