it depends on where in your Java code you're attempting to get the value of getX()
If Android has not already completed drawing the entire layout, cancelButton has not been drawn and the X is 0.0.
I've found that getting the value in onCreate() or onCreateView() is very easy with a post and runnable
cancelButton.post( new Runnable() {
@Override
public void run() {
float x = cancelButton.getX();
}
});
this ensures the button has been fully drawn before you attempt to use the value