سؤال

عندما أتطرق إلى أي مكان في الشاشة ، ستكون هذه النقطة توهجًا (لا شيء سوى الفلاش أو اللمعان) لبعض الوقت. كيف يتم فعل ذلك؟ أي مثال أو فكرة ؟؟ لا بد لي من التنفيذ لوضع أزرار عليها. بالضبط عندما أتطرق إلى الشاشة ، سوف يتوهج بعض الوقت ثم يظهر الزر على النقطة التي لمستها.

هل كانت مفيدة؟

المحلول

سيتعين عليك إنشاء طريقة عرض مخصصة وتجاوز ontouchevent والرسم. إليك مثال بسيط للغاية. يمكنك الرجوع إلى عرض مخصص في تخطيط XML إذا كنت تستخدم اسم الحزمة ie 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;
    }
}   
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top