我对 Bringtofront 方法有疑问。我一次使用许多图像。一切都在不停地移动。我想更改图像的 z 索引取决于它们的坐标。有什么办法吗?
当我移动图像时,我可能会检查每个图像的坐标。并按顺序使用 bringtofront ......但解决方案对我来说似乎并不明确。
编辑:
我添加了一些代码。计算并不那么重要。rl 是相对布局。当我单击 rl 时,会创建一个图像。问题是当我创建图像时,它会出现在旧图像上。我想要,哪个图像具有更大的 y 索引值。会在别人面前。
图片:http: //i.hizliresim.com/blkyzj.jpg
第 1 步:我创建了绿色正方形。第2步:我创建了棕色正方形。-> 棕色位于绿色的后面,因为绿色的 y 值较大。每次创建图像时,我都会检查 y 坐标,但图像也会移动。检查 y 值并在每次移动时都将其放在前面是有问题的。除了有 30 40 张图片...有没有办法像 image.zindex = ycoordinate*-1;
rl.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
final int finalX = (int) (Math.floor(arg1.getX() - (width * 5.93667 / 100))/(width*12.53290/100));
final int finalY = (int) (Math.floor(arg1.getY() - (height * 11.04784 / 100))/(height*7.73524/100));
characters.add(new Character());
characters.get(characters.size()-1).image = new ImageView(InPlay.this);
characters.get(characters.size()-1).image.setScaleType(ImageView.ScaleType.FIT_XY);
characters.get(characters.size()-1).image.setBackgroundResource(getId(towerid[activet], R.drawable.class));
characters.get(characters.size()-1).anim = (AnimationDrawable) characters.get(characters.size()-1).image.getBackground();
rl.addView(characters.get(characters.size()-1).image, characters.get(characters.size()-1).lp);
characters.get(characters.size()-1).image.getLayoutParams().width = (int) (width*12.53290/100) + (int)(characters.get(characters.size()-1).size * (width/10));
characters.get(characters.size()-1).image.getLayoutParams().height = (int) (height*7.73524/100) + (int)(characters.get(characters.size()-1).size * (height/10));
characters.get(characters.size() - 1).x= (float) ((finalX * (width*12.53290/100))+ (width * 5.93667 / 100)) - (float)(characters.get(characters.size()-1).size * (width/20));
characters.get(characters.size() - 1).y= (float) ((finalY * (height*7.73524/100))+ (height * 11.04784 / 100)) - (float)(characters.get(characters.size()-1).size * (height/10));
characters.get(characters.size()-1).image.setX((float) ((finalX * (width*12.53290/100))+ (width * 5.93667 / 100)) -(float)(characters.get(characters.size()-1).size * (width/20)));
characters.get(characters.size()-1).image.setY((float) ((finalY * (height*7.73524/100))+ (height * 11.04784 / 100)) - (float)(characters.get(characters.size()-1).size * (height/10)));
}