在我的应用程序中,当我尝试将图像覆盖在另一个图像上时,它不会立即发生,当我点击屏幕时它才会发生。我想说的是,这种无效方法适用于手机,但不适用于平板电脑(在我的情况下)。这是我的代码:
above.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
int positionn=0;
Log.d("before", ""+io);
//io is an ArrayList containing objects of all the images on the screen
if(io.size()==0)
{
}
else if(io.size()==1)// when only one image on the screen
{
p.bringToFront();// to overlay the image. here p is an imageView
}
else if(io.size()==2)// // when only one image on the screen
{
for(int a=0;a<io.size();a++)
{
if(p==io.get(a))
{
positionn=a; // to get the position of image which has been clicked
}
else
{
}
}
if(positionn==0)
{
p.bringToFront();
io.get(positionn).postInvalidate(); // to refersh the screen ,,, and is not working for tablet
io.get(positionn+1).postInvalidate();
System.out .println("checking");
Collections.swap(io,positionn,positionn+1);
}
else // when the screen has more than 2 images
{
}
}
else
{
for(int a=0;a<io.size();a++)
{
if(p==io.get(a))
{
positionn=a; // to get the positionn
}
else
{
}
}
Log.d(">>>>>>>>>>>>>>>>>>>.",""+positionn+"----------"+(io.size()-1));
if(positionn==io.size()-1)
{
// for last positionn,,,, since it do not required to be overlayed
}
else
{
try {
Collections.swap(io,positionn,positionn+1);
} catch (Exception e) {
e.printStackTrace();
}
Log.d("after", ""+io);
for (int a=0;a<io.size();a++)
{
// for each and every position
io.get(a).bringToFront();
io.get(a).invalidate();
}
}
}
for(int a=0;a<io.size();a++)
{
io.get(a).invalidate();
}
counter.start();
}
});