本文整理了Java中android.view.View.getLocationInWindow()
方法的一些代码示例,展示了View.getLocationInWindow()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。View.getLocationInWindow()
方法的具体详情如下:
包路径:android.view.View
类名称:View
方法名:getLocationInWindow
暂无
代码示例来源:origin: stackoverflow.com
View rootLayout = view.getRootView().findViewById(android.R.id.content);
int[] viewLocation = new int[2];
view.getLocationInWindow(viewLocation);
int[] rootLocation = new int[2];
rootLayout.getLocationInWindow(rootLocation);
int relativeLeft = viewLocation[0] - rootLocation[0];
int relativeTop = viewLocation[1] - rootLocation[1];
代码示例来源:origin: Hitomis/transferee
/**
* 获取 View 在屏幕坐标系中的坐标
*
* @param view 需要定位位置的 View
* @return 坐标系数组
*/
protected int[] getViewLocation(View view) {
int[] location = new int[2];
view.getLocationInWindow(location);
return location;
}
代码示例来源:origin: stackoverflow.com
public boolean dispatchTouchEvent(MotionEvent ev) {
View contentsView = findViewById(android.R.id.content);
int test1[] = new int[2];
contentsView.getLocationInWindow(test1);
int test2[] = new int[2];
contentsView.getLocationOnScreen(test2);
System.out.println(test1[1] + " " + test2[1]);
return super.dispatchTouchEvent(ev);
}
代码示例来源:origin: ZieIony/Carbon
public Point getLocationInWindow() {
int[] outLocation = new int[2];
super.getLocationInWindow(outLocation);
return new Point(outLocation[0], outLocation[1]);
}
代码示例来源:origin: stackoverflow.com
final ViewTreeObserver viewTreeObserver = getWindow().getDecorView().getViewTreeObserver();
viewTreeObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
View menuButton = findViewById(R.id.menu_refresh);
// This could be called when the button is not there yet, so we must test for null
if (menuButton != null) {
// Found it! Do what you need with the button
int[] location = new int[2];
menuButton.getLocationInWindow(location);
Log.d(TAG, "x=" + location[0] + " y=" + location[1]);
// Now you can get rid of this listener
viewTreeObserver.removeGlobalOnLayoutListener(this);
}
}
});
代码示例来源:origin: naman14/Timber
private void captureValues(TransitionValues transitionValues) {
final View view = transitionValues.view;
transitionValues.values.put(PROPERTY_BOUNDS, new Rect(
view.getLeft(), view.getTop(), view.getRight(), view.getBottom()
));
int[] position = new int[2];
transitionValues.view.getLocationInWindow(position);
transitionValues.values.put(PROPERTY_POSITION, position);
}
代码示例来源:origin: iammert/MaterialIntroView
@Override
public Point getPoint() {
int[] location = new int[2];
view.getLocationInWindow(location);
return new Point(location[0] + (view.getWidth() / 2), location[1] + (view.getHeight() / 2));
}
代码示例来源:origin: XunMengWinter/CircularAnim
public FullActivityBuilder(Activity activity, View triggerView) {
mActivity = activity;
int[] location = new int[2];
triggerView.getLocationInWindow(location);
final int cx = location[0] + triggerView.getWidth() / 2;
final int cy = location[1] + triggerView.getHeight() / 2;
mTriggerPoint = new Point(cx, cy);
}
代码示例来源:origin: iammert/MaterialIntroView
@Override
public Rect getRect() {
int[] location = new int[2];
view.getLocationInWindow(location);
return new Rect(
location[0],
location[1],
location[0] + view.getWidth(),
location[1] + view.getHeight()
);
}
代码示例来源:origin: bluelinelabs/Conductor
/**
* Constructor that will create a circular reveal from the center of the fromView parameter.
* @param fromView The view from which the circular reveal should originate
* @param containerView The view that hosts fromView
* @param duration The duration of the animation
* @param removesFromViewOnPush If true, the view being replaced will be removed from the view hierarchy on pushes
*/
public CircularRevealChangeHandler(@NonNull View fromView, @NonNull View containerView, long duration, boolean removesFromViewOnPush) {
super(duration, removesFromViewOnPush);
int[] fromLocation = new int[2];
fromView.getLocationInWindow(fromLocation);
int[] containerLocation = new int[2];
containerView.getLocationInWindow(containerLocation);
int relativeLeft = fromLocation[0] - containerLocation[0];
int relativeTop = fromLocation[1] - containerLocation[1];
cx = fromView.getWidth() / 2 + relativeLeft;
cy = fromView.getHeight() / 2 + relativeTop;
}
代码示例来源:origin: JZ-Darkal/AndroidHttpCapture
public boolean isShouldHideInput(View view, MotionEvent event) {
if (view != null && (view instanceof EditText)) {
int[] leftTop = {0, 0};
view.getLocationInWindow(leftTop);
//获取输入框当前的location位置
int left = leftTop[0];
int top = leftTop[1];
int bottom = top + view.getHeight();
int right = left + view.getWidth();
if (event.getX() > left && event.getX() < right
&& event.getY() > top && event.getY() < bottom) {
return false;
}
}
return true;
}
代码示例来源:origin: binIoter/GuideView
/**
* Rect在屏幕上去掉状态栏高度的绝对位置
*/
static Rect getViewAbsRect(View view, int parentX, int parentY) {
int[] loc = new int[2];
view.getLocationInWindow(loc);
Rect rect = new Rect();
rect.set(loc[0], loc[1], loc[0] + view.getMeasuredWidth(), loc[1] + view.getMeasuredHeight());
rect.offset(-parentX, -parentY);
return rect;
}
}
代码示例来源:origin: TakuSemba/Spotlight
public T setPoint(@NonNull View view) {
int[] location = new int[2];
view.getLocationInWindow(location);
int x = location[0] + view.getWidth() / 2;
int y = location[1] + view.getHeight() / 2;
return setPoint(x, y);
}
代码示例来源:origin: andkulikov/Transitions-Everywhere
private void captureValues(TransitionValues values) {
View view = values.view;
if (ViewUtils.isLaidOut(view, false) || view.getWidth() != 0 || view.getHeight() != 0) {
values.values.put(PROPNAME_BOUNDS, new Rect(view.getLeft(), view.getTop(),
view.getRight(), view.getBottom()));
values.values.put(PROPNAME_PARENT, values.view.getParent());
if (mReparent) {
values.view.getLocationInWindow(tempLocation);
values.values.put(PROPNAME_WINDOW_X, tempLocation[0]);
values.values.put(PROPNAME_WINDOW_Y, tempLocation[1]);
}
if (mResizeClip) {
values.values.put(PROPNAME_CLIP, ViewUtils.getClipBounds(view));
}
}
}
代码示例来源:origin: GitLqr/LQRWeChat
/**
* 判断popupWindow是否显示在条目的下方
*
* @param itemView
* @return
*/
private static boolean isShowBottom(Activity context, View itemView) {
// 得到屏幕的高度
// int heightPixels =
// getResources().getDisplayMetrics().heightPixels;//方式1
int screenHeight = context.getWindowManager().getDefaultDisplay().getHeight();// 方式2
int[] location = new int[2];
// location[0]-->x
// location[1]-->y
itemView.getLocationInWindow(location);
// 得到itemView在屏幕中Y轴的值
int itemViewY = location[1];
// 得到itemView距离屏幕底部的距离
int distance = screenHeight - itemViewY - itemView.getHeight();
if (distance < itemView.getHeight()) {// 条目下方放不下popupWindow
return false;
} else {// 条目下方放得下popupWindow
return true;
}
}
代码示例来源:origin: pchmn/MaterialChipsInput
@Override
public void onClick(View v) {
// get chip position
int[] coord = new int[2];
v.getLocationInWindow(coord);
final DetailedChipView detailedChipView = mChipsInput.getDetailedChipView(getItem(position));
setDetailedChipViewPosition(detailedChipView, coord);
// delete button
detailedChipView.setOnDeleteClicked(new View.OnClickListener() {
@Override
public void onClick(View v) {
removeChip(position);
detailedChipView.fadeOut();
}
});
}
});
代码示例来源:origin: jeasonlzy/NineGridView
@Override
protected void onImageItemClick(Context context, NineGridView nineGridView, int index, List<ImageInfo> imageInfo) {
for (int i = 0; i < imageInfo.size(); i++) {
ImageInfo info = imageInfo.get(i);
View imageView;
if (i < nineGridView.getMaxSize()) {
imageView = nineGridView.getChildAt(i);
} else {
//如果图片的数量大于显示的数量,则超过部分的返回动画统一退回到最后一个图片的位置
imageView = nineGridView.getChildAt(nineGridView.getMaxSize() - 1);
}
info.imageViewWidth = imageView.getWidth();
info.imageViewHeight = imageView.getHeight();
int[] points = new int[2];
imageView.getLocationInWindow(points);
info.imageViewX = points[0];
info.imageViewY = points[1] - statusHeight;
}
Intent intent = new Intent(context, ImagePreviewActivity.class);
Bundle bundle = new Bundle();
bundle.putSerializable(ImagePreviewActivity.IMAGE_INFO, (Serializable) imageInfo);
bundle.putInt(ImagePreviewActivity.CURRENT_ITEM, index);
intent.putExtras(bundle);
context.startActivity(intent);
((Activity) context).overridePendingTransition(0, 0);
}
代码示例来源:origin: qiujuer/Genius-Android
private void updateLayoutParamsForPosition(View anchor, WindowManager.LayoutParams p, int yOffset) {
measureFloater();
int measuredHeight = mPopupView.getMeasuredHeight();
int paddingBottom = mPopupView.mMarker.getPaddingBottom();
anchor.getLocationInWindow(mDrawingLocation);
p.x = 0;
p.y = mDrawingLocation[1] - measuredHeight + yOffset + paddingBottom;
p.width = screenSize.x;
p.height = measuredHeight;
}
代码示例来源:origin: Dimezis/BlurView
/**
* setup matrix to draw starting from blurView's position
*/
private void setupInternalCanvasMatrix() {
blurView.getDrawingRect(relativeViewBounds);
if (shouldTryToOffsetCoords) {
try {
rootView.offsetDescendantRectToMyCoords(blurView, relativeViewBounds);
} catch (IllegalArgumentException e) {
// BlurView is not a child of the rootView (i.e. it's in Dialog)
// Fallback to regular coordinates system
shouldTryToOffsetCoords = false;
}
} else {
blurView.getLocationInWindow(locationInWindow);
relativeViewBounds.offset(locationInWindow[0], locationInWindow[1]);
}
float scaleFactorX = scaleFactor * roundingWidthScaleFactor;
float scaleFactorY = scaleFactor * roundingHeightScaleFactor;
float scaledLeftPosition = -relativeViewBounds.left / scaleFactorX;
float scaledTopPosition = -relativeViewBounds.top / scaleFactorY;
float scaledTranslationX = blurView.getTranslationX() / scaleFactorX;
float scaledTranslationY = blurView.getTranslationY() / scaleFactorY;
internalCanvas.translate(scaledLeftPosition - scaledTranslationX, scaledTopPosition - scaledTranslationY);
internalCanvas.scale(1f / scaleFactorX, 1f / scaleFactorY);
}
代码示例来源:origin: nickbutcher/plaid
ReflowData(@NonNull Reflowable reflowable) {
text = reflowable.getText();
textSize = reflowable.getTextSize();
textColor = reflowable.getTextColor();
fontResId = reflowable.getFontResId();
final View view = reflowable.getView();
int[] loc = new int[2];
view.getLocationInWindow(loc);
bounds = new Rect(loc[0], loc[1], loc[0] + view.getWidth(), loc[1] + view.getHeight());
textPosition = reflowable.getTextPosition();
textHeight = reflowable.getTextHeight();
lineSpacingAdd = reflowable.getLineSpacingAdd();
lineSpacingMult = reflowable.getLineSpacingMult();
textWidth = reflowable.getTextWidth();
breakStrategy = reflowable.getBreakStrategy();
letterSpacing = reflowable.getLetterSpacing();
maxLines = reflowable.getMaxLines();
}
内容来源于网络,如有侵权,请联系作者删除!