2010-03-27 12 views
7

cuando toco donde esté en la pantalla, ese punto estará iluminado (nada más que como un destello o brillante) durante algún tiempo. ¿como hacer eso? algún ejemplo o idea? tengo que implementar para ponerle botones. exactamente cuando toco la pantalla, brillará un poco y luego el botón aparecerá en el punto donde toqué.brilla cuando tocas la pantalla en android?

Respuesta

11

Vas a tener que crear una vista personalizada y anular ontouchevent y dibujar. Aquí hay un ejemplo muy simple. puede hacer referencia a una vista personalizada en un diseño xml si usa el nombre del paquete, es decir, com.test.CustomView.

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

¿Qué sucede si tengo un ViewPager debajo de él, que necesita el onTouchEvent? – Machado

Cuestiones relacionadas