2013-04-08 2 views
0

내 맞춤 ImageView 클래스 AvatarView에서 클릭 효과를 시도하고 있습니다.클릭 효과가있는 이미지

그 코드를 사용하고 있습니다 :

 // **** Listener onTouch ****. 

    // Añadimos un listener para su pulsación. 
    this.setOnTouchListener(new OnTouchListener() { 

     public boolean onTouch(View v, MotionEvent event) { 

      switch (event.getAction()) { 

       case MotionEvent.ACTION_DOWN: 

        // Establecemos un filtrado de color. 
        AvatarView.this.setColorFilter(0xe0f47521, PorterDuff.Mode.SRC_ATOP); 
        AvatarView.this.invalidate(); 
        break; 

       case MotionEvent.ACTION_UP: 

        // Eliminamos el filtrado de color. 
        //AvatarView.this.clearColorFilter(); 
        AvatarView.this.setColorFilter(null); 
        AvatarView.this.invalidate(); 
        break; 


      } 

      return false; 
     } 
    }); 

이 코드는 내 2.3 전화에서 완벽하게 작동을하지만 이미지가 사라지고 다시 나타나지 않기 때문에 내 4.1 태블릿에 실패합니다.

나는 해결책을 찾지 못했습니다. 어떤 생각?

감사합니다.

답변

0

마지막으로, 나는 해결책을 발견 : 그것은 드로어 블을 필요가있다 :

 // **** Listener onTouch ****. 

    // Añadimos un listener para su pulsación. 
    this.setOnTouchListener(new OnTouchListener() { 

     public boolean onTouch(View v, MotionEvent event) { 

      switch (event.getAction()) { 

       case MotionEvent.ACTION_DOWN: 

        // Establecemos un filtrado de color. 
        AvatarView.this.getDrawable().setColorFilter(0xe0f47521, PorterDuff.Mode.SRC_ATOP); 
        AvatarView.this.invalidate(); 
        break; 

       case MotionEvent.ACTION_UP: 

        // Eliminamos el filtrado de color. 
        AvatarView.this.getDrawable().clearColorFilter(); 
        AvatarView.this.invalidate(); 
        break; 

       case MotionEvent.ACTION_CANCEL: 

        // Eliminamos el filtrado de color. 
        AvatarView.this.getDrawable().clearColorFilter(); 
        AvatarView.this.invalidate(); 
        break; 

      } 

      return false; 
      //return true; 
     } 
    }); 

지금, 그것은 잘 작동합니다.

진실 또는 거짓을 돌려 주면 아무도 나에게 말할 수 있습니까? 차이점이 뭐야?

감사합니다.

+1

false는 터치 이벤트가 소비되지 않았 음을 의미하므로 기본보기로 전파됩니다. True는 이벤트를 소비하므로 아이들은 이벤트를 알지 못합니다. – AndacAydin

관련 문제