发光时的Android触摸屏? [英] glow when touch the screen in android?
问题描述
当我抚摸等。无论在屏幕这一点上会发光(不过像闪光或闪光的)一段时间。如何做到这一点?任何例子或者想法?我要实现把上的按钮。什么时候我触摸屏幕就会发光一段时间,然后按钮将出现在那里我碰到了点。
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 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.
推荐答案
您将不得不创建一个自定义视图,并覆盖的onTouchEvent和借鉴。这里是一个非常简单的例子。如果你使用的软件包名称即com.test.CustomView你可以参考自定义视图在一个XML布局。
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;
}
}
这篇关于发光时的Android触摸屏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!