我想在自定义视图中的 onDraw() 方法中制作类似拼图(将图像放在一起)的东西。所以起初我称之为它并展示我的整个谜题。但过了一段时间我想改变我的拼图图像。因此,当我从另一个线程更改图像源并 invalidate() 时,可能会强制关闭应用程序。从您的角度来看,我应该怎么做才能达到这个目标?这是我的代码:
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
canvas.drawARGB(100, 255, 255, 0);
canvas.translate(posX, posY);
canvas.scale(imageScale,imageScale);
InitDrawing(canvas);
}
public void InitDrawing(Canvas canvas)
{
for (int a = 0 ; a < 5 ;a++)
{
for(int i =0 ; i<4 ; i++)
{
canvas.drawBitmap(toop,(toop.getWidth()*i ) ,(toop.getHeight()*a) , null);
downloading = true;
IMGnotExisting = true;
Log.i("Canvas loop", "Showing");
}
}
}
public class SDChecker implements Runnable
{
public SDChecker()
{
// String name = s;
PauseTHR = new Object();
pause = false;
}
@Override
public void run()
{
// while( true)
// {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
File file = new File(Environment.getExternalStorageDirectory()+ "/GreatMap","tile0.jpg");
if (file.exists())
{
toop = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+"/GreatMap/tile0.jpg");
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
invalidate();
Log.i("Create bit map", "Bitmap create");
// Toast.makeText(getContext(), "loadmap tile", Toast.LENGTH_SHORT);
IMGnotExisting = false;
}
else
{
IMGnotExisting = true;
}
}
}