0
我想在自定義視圖中的onDraw()方法中製作類似於拼圖(將圖像放在一起)的東西。所以起初我打電話給我,並展示我的整個難題。 但過了一段時間我想改變我的拼圖圖像。所以當我從另一個線程更改圖像的來源和invalidate(),但可能應用程序將被迫關閉。 從你的角度來看,我應該怎麼做才能達到這個目標? 這裏是我的代碼:未能在視圖中調用onDraw方法
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;
}
}
}