下面列出了android.support.v4.view.ViewCompat#getX ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Detect if the dragView actual position is above the
* limit determined with the @param dragLimit.
*
* @return Use a dimension and compare with the dragged
* axis position.
*/
boolean isDragViewAboveTheLimit() {
int parentSize;
float viewAxisPosition;
switch (dragPosition) {
case LEFT:
parentSize = dragView.getWidth();
viewAxisPosition = -ViewCompat.getX(dragView) + (parentSize * dragLimit);
break;
case RIGHT:
parentSize = dragView.getWidth();
viewAxisPosition = ViewCompat.getX(dragView) + (parentSize * dragLimit);
break;
case TOP:
default:
parentSize = dragView.getHeight();
viewAxisPosition = ViewCompat.getY(dragView) + (parentSize * dragLimit);
break;
case BOTTOM:
parentSize = dragView.getHeight();
viewAxisPosition = -ViewCompat.getY(dragView) + (parentSize * dragLimit);
break;
}
return parentSize < viewAxisPosition;
}
public static float getX(final @NonNull View v) {
if (Build.VERSION.SDK_INT >= 11) {
return ViewCompat.getX(v);
} else {
return ((LinearLayout.LayoutParams) v.getLayoutParams()).leftMargin;
}
}
public static float getX(final @NonNull View v) {
if (VERSION.SDK_INT >= 11) {
return ViewCompat.getX(v);
} else {
return ((LayoutParams)v.getLayoutParams()).leftMargin;
}
}
FabInfo(FloatingActionButton fab) {
int[] location = new int[2];
fab.getLocationInWindow(location);
width = fab.getMeasuredWidth();
height = fab.getMeasuredHeight();
topLeft = new Pointer(location[0], location[1]);
center = new Pointer(topLeft.x + width / 2, topLeft.y + height / 2);
bottomRight = new Pointer(topLeft.x + width, topLeft.y + height);
relativeTopLeft = new Pointer(ViewCompat.getX(fab), ViewCompat.getY(fab));
relativeCenter = new Pointer(relativeTopLeft.x + width / 2, relativeTopLeft.y + height / 2);
relativeBottomRight = new Pointer(relativeTopLeft.x + width, relativeTopLeft.y + height);
radius = Math.min(width / 2, MdCompat.dpToPx(FAB_SIZE));
}
public static float centerX(View view) {
return ViewCompat.getX(view) + view.getWidth() / 2f;
}
private float centerX(View view) {
return ViewCompat.getX(view) + view.getWidth() / 2f;
}
public static float centerX(View view) {
return ViewCompat.getX(view) + view.getMeasuredWidth() / 2;
}