Place the image (overlay) on top of x, y of another image (background)

I need to place the image dynamically at runtime on another image exactly in the x, y of the background image .

I have the following data:

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 upper left corner of the overlay.

Note. x, y of the image Overlay is related to the background image, not the entire screen. The background image may stretch when you hide the ActionBar. The layout_width and layout_height of the background image are set to match_parent. and scaleType is the "center".

with the code below:

@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

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

+2
source share
1 answer

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

This is an advanced ImageView that supports multiple Drawable layers.

+1
source

Source: https://habr.com/ru/post/1499154/


All Articles