我需要在运行时动态地将图像放在另一个图像上,正好在背景图像的x,y处。在另一个图像(背景)的x,y上放置图像(覆盖图)
我有以下细节:
叠印图像属性(红):X = 58,Y = 232,H = 266,W = 431
背景图像(黑色):match_parent,W = 1024, h = 768
这里x,y是叠加层的左上角。
注意:覆盖图像的x,y是相对于背景图像而不是整个屏幕布局。隐藏ActionBar时,背景图片可能会伸展。背景图片的layout_width和layout_height设置为match_parent。 scaleType是“中心”。
与下面的代码:
@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);
}
从以上代码:
[我想要什么]
从这么多的解决方案和建议,没有为我工作。相信我,我不会在没有尝试的情况下发布这个问题。
集填充您的内部RelativeLayout的 –
红色长方形你没有设置的LayoutParams的x和y扩展的ImageView你想要重叠的图像..你只具体的高度和宽度(图像的大小),但不是它的位置 –