实施点击图表

时间:2016-12-19 09:54:09

标签: android android-layout

我有一个图像中显示的布局。 enter image description here我要实施单独点击所有戒指,即1,2,3,4。
如何做到这一点?
请帮助!!

1 个答案:

答案 0 :(得分:0)

看起来应该是这样的。

public class CustomProgressBar extends ProgressBar {


    private boolean shouldHandleClick(float x, float y) {
        /*
         return true if click is within the ring

         For this to work you will have to calculate where exactly the ring is, 
         then its just a matter of determining whether the click is inside the area or not.
         Might take some doing.
         */


    }

    // thanks to http://stackoverflow.com/questions/17831395/how-can-i-detect-a-click-in-an-ontouch-listener
    @Override
    public boolean onTouch(View v, MotionEvent event) {

        // this will check if its a click and calculate if it's within your area of interest.
        if (isAClick(startX, endX, startY, endY) && !shouldHandleClick(event.getX(),event.getY()))
            return false;

        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            startX = event.getX();
            startY = event.getY();
            break;
        case MotionEvent.ACTION_UP: 
            float endX = event.getX();
            float endY = event.getY();
            if (isAClick(startX, endX, startY, endY)) { 
                launchFullPhotoActivity(imageUrls);// WE HAVE A CLICK!!
            }
            break;
        default:
            return super.onTouch(v,event);
        }

        return true;
    }

    private boolean isAClick(float startX, float endX, float startY, float endY) {
        float differenceX = Math.abs(startX - endX);
        float differenceY = Math.abs(startY - endY);
        if (differenceX > CLICK_ACTION_THRESHHOLD/* =5 */ || differenceY > CLICK_ACTION_THRESHHOLD) {
            return false;
        }
        return true;
    } 
}