2010-03-27 4 views
7

내가 화면에 터치하면 그 지점이 반짝 거릴 것입니다 (플래시 나 반짝임 같은 느낌). 그렇게하는 방법? 어떤 예 또는 아이디어 ?? 나는 그것에 버튼을 넣어 구현해야합니다. 정확히 내가 화면을 만질 때 그것은 약간의 시간을 비 춥니 다. 그러면 터치 한 지점에 버튼이 나타날 것입니다.안드로이드에서 화면을 터치하면 빛납니다?

답변

11

사용자 정의보기를 만들고 ontouchevent를 덮어 쓰고 그릴 필요가 있습니다. 여기에 아주 간단한 예가 있습니다. 패키지 이름, 즉 com.test.CustomView를 사용하면 xml 레이아웃에서 사용자 정의보기를 참조 할 수 있습니다.

public class CustomView extends ImageView{ 
    public CustomView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
    } 
    public CustomView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 
    public CustomView(Context context) { 
     super(context); 
    } 
    boolean drawGlow = false; 
    //this is the pixel coordinates of the screen 
    float glowX = 0; 
    float glowY = 0; 
    //this is the radius of the circle we are drawing 
    float radius = 20; 
    //this is the paint object which specifies the color and alpha level 
    //of the circle we draw 
    Paint paint = new Paint(); 
    { 
     paint.setAntiAlias(true); 
     paint.setColor(Color.WHITE); 
     paint.setAlpha(50); 
    }; 

    @Override 
    public void draw(Canvas canvas){ 
     super.draw(canvas); 
     if(drawGlow) 
      canvas.drawCircle(glowX, glowY, radius, paint); 
    } 
    @Override 
    public boolean onTouchEvent(MotionEvent event){ 
     if(event.getAction() == MotionEvent.ACTION_DOWN){ 
      drawGlow = true; 
     }else if(event.getAction() == MotionEvent.ACTION_UP) 
      drawGlow = false; 

     glowX = event.getX(); 
     glowY = event.getY(); 
     this.invalidate(); 
     return true; 
    } 
} 
+0

아래에 ViewPager가 있는데 onTouchEvent가 필요한 경우 어떻게해야합니까? – Machado

관련 문제