下面列出了android.view.ViewGroup#offsetDescendantRectToMyCoords ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void initPeekHeight(DialogInterface dialog)
{
if (dialog == null) {
return;
}
BottomSheetDialog bottomSheet = (BottomSheetDialog) dialog;
FrameLayout layout = (FrameLayout) bottomSheet.findViewById(android.support.design.R.id.design_bottom_sheet); // for AndroidX, resource is renamed to com.google.android.material.R.id.design_bottom_sheet
if (layout != null)
{
BottomSheetBehavior behavior = BottomSheetBehavior.from(layout);
ViewGroup dialogLayout = (LinearLayout) bottomSheet.findViewById(R.id.moondialog_layout);
View divider1 = bottomSheet.findViewById(R.id.divider1);
if (dialogLayout != null && divider1 != null)
{
Rect headerBounds = new Rect();
divider1.getDrawingRect(headerBounds);
dialogLayout.offsetDescendantRectToMyCoords(divider1, headerBounds);
behavior.setPeekHeight(headerBounds.top);
} else {
behavior.setPeekHeight(-1);
}
}
}
@Override
public Rect get(View object) {
ViewGroup viewGroup = (ViewGroup) object.getParent();
Rect rect = new Rect();
viewGroup.offsetDescendantRectToMyCoords(viewGroup, rect);
return rect;
}
public Rect findLocationWithView(View view)
{
ViewGroup root = (ViewGroup)getMainUpView().getParent();
Rect rect = new Rect();
root.offsetDescendantRectToMyCoords(view, rect);
return rect;
}
@Override
public void offsetDescendantRect(ViewGroup parent, View child, Rect rect) {
parent.offsetDescendantRectToMyCoords(child, rect);
// View#offsetDescendantRectToMyCoords includes scroll offsets of the last child.
// We need to reverse it here so that we get the rect of the view itself rather
// than its content.
rect.offset(child.getScrollX(), child.getScrollY());
}
@Override
public void offsetDescendantRect(ViewGroup parent, View child, Rect rect) {
parent.offsetDescendantRectToMyCoords(child, rect);
// View#offsetDescendantRectToMyCoords includes scroll offsets of the last child.
// We need to reverse it here so that we get the rect of the view itself rather
// than its content.
rect.offset(child.getScrollX(), child.getScrollY());
}
public T bounds(Rect toValue) {
ViewGroup viewGroup = (ViewGroup) mView.getParent();
Rect rect = new Rect();
viewGroup.offsetDescendantRectToMyCoords(viewGroup, rect);
return bounds(rect, toValue);
}
@Override
public void offsetDescendantRect(ViewGroup parent, View child, Rect rect) {
parent.offsetDescendantRectToMyCoords(child, rect);
}
@Override
public void offsetDescendantRect(ViewGroup parent, View child, Rect rect) {
parent.offsetDescendantRectToMyCoords(child, rect);
}
@Override
public void offsetDescendantRect(ViewGroup parent, View child, Rect rect) {
parent.offsetDescendantRectToMyCoords(child, rect);
}
private int[] getCenterClickedView(ViewGroup from) {
Rect clickedViewRect = new Rect();
clickedView.getDrawingRect(clickedViewRect);
from.offsetDescendantRectToMyCoords(clickedView, clickedViewRect);
return new int[] {(int) clickedViewRect.exactCenterX(), (int) clickedViewRect.exactCenterY()};
}
@OnClick(R.id.reset) void resetUi(View resetCard) {
cardsLine.setVisibility(View.INVISIBLE);
final View target = ButterKnife.findById(this, R.id.activator);
// Coordinates of circle initial point
final ViewGroup parent = (ViewGroup) activatorMask.getParent();
final Rect bounds = new Rect();
final Rect maskBounds = new Rect();
target.getDrawingRect(bounds);
activatorMask.getDrawingRect(maskBounds);
parent.offsetDescendantRectToMyCoords(target, bounds);
parent.offsetDescendantRectToMyCoords(activatorMask, maskBounds);
maskElevation = activatorMask.getCardElevation();
activatorMask.setCardElevation(0);
final int cX = maskBounds.centerX();
final int cY = maskBounds.centerY();
final Animator circularReveal = ViewAnimationUtils.createCircularReveal(activatorMask, cX, cY,
(float) Math.hypot(maskBounds.width() * .5f, maskBounds.height() * .5f),
target.getWidth() / 2f, View.LAYER_TYPE_HARDWARE);
final float c0X = bounds.centerX() - maskBounds.centerX();
final float c0Y = bounds.centerY() - maskBounds.centerY();
AnimatorPath path = new AnimatorPath();
path.moveTo(0, 0);
path.curveTo(0, 0, 0, c0Y, c0X, c0Y);
ObjectAnimator pathAnimator = ObjectAnimator.ofObject(this, "maskLocation", new PathEvaluator(),
path.getPoints().toArray());
AnimatorSet set = new AnimatorSet();
set.playTogether(circularReveal, pathAnimator);
set.setInterpolator(new FastOutSlowInInterpolator());
set.setDuration(SLOW_DURATION);
set.addListener(new AnimatorListenerAdapter() {
@Override public void onAnimationEnd(Animator animation) {
activatorMask.setCardElevation(maskElevation);
activatorMask.setVisibility(View.INVISIBLE);
circlesLine.setVisibility(View.VISIBLE);
executeCirclesDropDown();
target.setEnabled(true);
}
});
set.start();
}
@Override
public void offsetDescendantRect(ViewGroup parent, View child, Rect rect) {
parent.offsetDescendantRectToMyCoords(child, rect);
}
@Override
public void offsetDescendantRect(ViewGroup parent, View child, Rect rect) {
parent.offsetDescendantRectToMyCoords(child, rect);
}
public Rect findLocationWithView(View view) {
ViewGroup root = (ViewGroup) getMainUpView().getParent();
Rect rect = new Rect();
root.offsetDescendantRectToMyCoords(view, rect);
return rect;
}
public Rect findLocationWithView(View view) {
ViewGroup root = (ViewGroup) vf.getParent();
Rect rect = new Rect();
root.offsetDescendantRectToMyCoords(view, rect);
return rect;
}
public Rect findLocationWithView(View view) {
ViewGroup root = (ViewGroup) this.getParent();
Rect rect = new Rect();
root.offsetDescendantRectToMyCoords(view, rect);
return rect;
}
protected Rect findLocationWithView(View view) {
ViewGroup root = (ViewGroup) view.getParent();
Rect rect = new Rect();
root.offsetDescendantRectToMyCoords(view, rect);
return rect;
}
public Rect findLocationWithView(View view) {
ViewGroup root = (ViewGroup) getMainUpView().getParent();
Rect rect = new Rect();
root.offsetDescendantRectToMyCoords(view, rect);
return rect;
}
@Override
public void offsetDescendantRect(ViewGroup parent, View child, Rect rect) {
parent.offsetDescendantRectToMyCoords(child, rect);
}
public static int getRelativeTop(View myView, ViewGroup parentView) {
Rect offsetViewBounds = new Rect();
myView.getDrawingRect(offsetViewBounds);
parentView.offsetDescendantRectToMyCoords(myView, offsetViewBounds);
return offsetViewBounds.top;
}