Get The Measures of Popup Window
You won't get the height or width of the view, which hasn't been drawn on the screen.
pupLayout.getWidth()
// this will give you 0
You need to get the width like this
int width = MeasureSpec.makeMeasureSpec(0, MeasureSpec. UNSPECIFIED);
Use it like this
View pupLayout = inflater.inflate(R.layout.linearlayout_popup, base);
pupLayout.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int x = location[0] - (int) ((pupLayout.getMeasuredWidth() - v.getWidth()) / 2 );