简体   繁体   English

Android中两个重叠的ImageView

[英]Two overlapping ImageViews in Android

In a ViewGroup I want to put two ImageViews overlapping: The imageview A have a transparent background and some drawing across the image, the imageview B . 在ViewGroup中,我希望将两个ImageView重叠: imageview A具有透明背景和一些图像,即imageview B.

I want both them to be at the same place and have the same size (but can't fix their size in the XML because if the image at ivB changes the ivA should resize to match the new size. 我希望它们在同一个地方并具有相同的大小(但无法在XML中修复它们的大小,因为如果ivB处的图像发生更改,则ivA应调整大小以匹配新大小。

Since the ivA source image does not change I tried ivA.getWidth() and ivA .getHeight() for setting the ivB size but their value are 0,0 in the onCreate() method. 由于ivA源图像没有改变,我尝试使用ivA.getWidth()和ivA .getHeight()来设置ivB大小,但是在onCreate()方法中它们的值是0,0。

Is there some "easy" way of doing this? 这样做有一些“简单”的方法吗?

Override the ImageView and in onLayout() you can get proper width or height after calling super.onLayout(). 覆盖ImageView,在onLayout()中,调用super.onLayout()后可以获得正确的宽度或高度。 Try setting values in the place. 尝试在该位置设置值。

Try getting the dimensions in onWindowFocusChangedListener . 尝试获取onWindowFocusChangedListener的维度。

An easier way would be putting the ImageViews in a FrameLayout (which is built to put Views on top of the other), and resize the FrameLayout instead. 一种更简单的方法是将ImageView放在FrameLayout中(构建为将Views放在另一个上面),然后调整FrameLayout的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM