glow when touch the screen in android?

前端 未结 1 1682
情深已故
情深已故 2021-02-09 07:11

when i touch whereever in the screen that point will be glow(nothing but like a flash or glittering) for some time. how to do that? any example or idea?? i have to implement to

1条回答
  •  别那么骄傲
    2021-02-09 08:04

    Your going to have to create a custom view and override ontouchevent and draw. Here's a very simple example. you can reference a custom view in an xml layout if you use the package name i.e. 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 讨论(0)
提交回复
热议问题