2014-10-29 126 views
0

我有一個custom ImageView,我可以繪製,縮放和繪製點(座標)。我需要使用按鈕刷新imageView(無效不起作用)

I have a button "reset" which delete the coordinates i draw 

但是我的imageView不會刷新,當我點擊它後刷新,當我觸摸屏幕。

會看到一些代碼

這裏buttons- btnRes

onClick是按鈕我需要幫助!

//this method is on the "Main extends Activity" 
public void onClick(View v) { 
     switch(v.getId()){ 
     case R.id.btnFin: 
      break; 
     case R.id.btnInv: 
      break; 
     case R.id.btnRes://start over 
      Imagen.listaPtos.clear(); 
      //refreshing image 
      imagen.invalidate();//dont works 
      imagen.refreshDrawableState();//dont works neither 
      break; 
     } 
    } 

約我班imagen畫質一些事情代碼

public class Imagen extends ImageView 

static ArrayList <Marking> listaPtos = new ArrayList<Marking>(); 

一些代碼取自imagen

@Override 
public void onDraw(Canvas c){ 
    Log.d("onDraw","pinta="+pinta); 
    c.drawBitmap(bitmap, matrix, paintFondo); 

    if(listaPtos!=null){ 
     for(Marking mark:listaPtos){     
      c.drawBitmap(cruz, mark.x, mark.y, paintPuntos); 
     } 
    } 
} 

//for coordinates 
class Marking{ 
int x; 
int y; 
Marking(int x, int y){ 
    this.x = x; 
    this.y = y; 
} 
Marking(){} 
int getX(){ 
    return x; 
} 
int getY(){ 
    return y; 
} 
void setX(int x){ 
    this.x = x; 
} 
void setY(int y){ 
    this.y = y; 
} 

}

任何想法後,明白了?

+0

postInvalidate()不工作也不:/ – 2014-10-29 12:13:20

+0

圖像。 onDraw(新的畫布)也不工作 – 2014-10-29 12:15:15

回答

0

我用這個代碼insithe的onDraw解決這個問題:

((Main) context).runOnUiThread(new Runnable() { 
      @Override 
      public void run() { 

       Imagen.this.invalidate(); 

      } 
    }); 

不是最好的解決辦法,但誰的作品

THX的一個:https://stackoverflow.com/a/21732444/4116091