glow when touch the screen in android?
when i touch whereever in the screen that point will be glow(nothi开发者_如何学Gong but like a flash or glittering) for some time. how to do that? any example or idea?? i have to implement to put buttons on it. exactly when i touch the screen it will glow some time and then the button will appear on the point where i touched.
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;
}
}
精彩评论