答案 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;
}
}