public static float getVisibleWidthRatio(ViewGroup parent, View child) {
float ratio = 0f;
if (child.getRight() > parent.getPaddingStart() && child.getLeft() < parent.getWidth() - parent.getPaddingEnd()) { //可见区域范围
float visibleWidth = child.getWidth();
if (child.getLeft() < parent.getPaddingStart()) {//左边隐藏
visibleWidth = child.getWidth() + child.getLeft();
}
if (child.getRight() > parent.getWidth() - parent.getPaddingEnd()) { // 右边隐藏
visibleWidth = child.getWidth() - (child.getRight() - (parent.getWidth() - parent.getPaddingEnd()));
}
ratio = visibleWidth / child.getWidth();
}
return ratio;
}