本文整理汇总了Java中android.view.View.getLocationInWindow方法的典型用法代码示例。如果您正苦于以下问题:Java View.getLocationInWindow方法的具体用法?Java View.getLocationInWindow怎么用?Java View.getLocationInWindow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.View
的用法示例。
在下文中一共展示了View.getLocationInWindow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showMoreKeysPanel
import android.view.View; //导入方法依赖的package包/类
@Override
public void showMoreKeysPanel(final View parentView, final Controller controller,
final int pointX, final int pointY, final KeyboardActionListener listener) {
mController = controller;
mListener = listener;
final View container = getContainerView();
// The coordinates of panel's left-top corner in parentView's coordinate system.
// We need to consider background drawable paddings.
final int x = pointX - getDefaultCoordX() - container.getPaddingLeft() - getPaddingLeft();
final int y = pointY - container.getMeasuredHeight() + container.getPaddingBottom()
+ getPaddingBottom();
parentView.getLocationInWindow(mCoordinates);
// Ensure the horizontal position of the panel does not extend past the parentView edges.
final int maxX = parentView.getMeasuredWidth() - container.getMeasuredWidth();
final int panelX = Math.max(0, Math.min(maxX, x)) + CoordinateUtils.x(mCoordinates);
final int panelY = y + CoordinateUtils.y(mCoordinates);
container.setX(panelX);
container.setY(panelY);
mOriginX = x + container.getPaddingLeft();
mOriginY = y + container.getPaddingTop();
controller.onShowMoreKeysPanel(this);
}
示例2: showAsDropDown
import android.view.View; //导入方法依赖的package包/类
/**
* fix showAsDropDown when android api ver is over N
* <p>
* https://code.google.com/p/android/issues/detail?id=221001
*
* @param anchor
* @param xoff
* @param yoff
* @param gravity
*/
@Override
public void showAsDropDown(View anchor, int xoff, int yoff, int gravity) {
if (isFixAndroidN && anchor != null) {
int[] anchorLocation = new int[2];
anchor.getLocationInWindow(anchorLocation);
Activity activity = (Activity) anchor.getContext();
xoff = anchorLocation[0] + xoff;
yoff = anchorLocation[1] + anchor.getHeight() + yoff;
setFocusable(false);
super.showAtLocation((activity).getWindow().getDecorView(), Gravity.NO_GRAVITY, xoff, yoff);
initSystemBar(getContentView());
setFocusable(true);
update();
} else {
if (isOverAndroidN) {
setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
}
setFocusable(false);
super.showAsDropDown(anchor, xoff, yoff, gravity);
initSystemBar(getContentView());
setFocusable(true);
update();
}
}
示例3: isShouldHideInput
import android.view.View; //导入方法依赖的package包/类
public boolean isShouldHideInput(View v, MotionEvent event) {
if (v != null && (v instanceof EditText)) {
int[] leftTop = {0, 0};
//获取输入框当前的location位置
v.getLocationInWindow(leftTop);
int left = leftTop[0];
int top = leftTop[1];
int bottom = top + v.getHeight();
int right = left + v.getWidth();
if (event.getX() > left && event.getX() < right
&& event.getY() > top && event.getY() < bottom) {
// 点击的是输入框区域,保留点击EditText的事件
return false;
} else {
return true;
}
}
return false;
}
示例4: shortToast
import android.view.View; //导入方法依赖的package包/类
public static void shortToast(View view, Window window, @StringRes int text) {
Toast toast = makeToast(CoreApp.getInstance().getString(text), Toast.LENGTH_SHORT);
Rect rect = new Rect();
window.getDecorView().getWindowVisibleDisplayFrame(rect);
int[] viewLocation = new int[2];
view.getLocationInWindow(viewLocation);
int viewLeft = viewLocation[0] - rect.left;
int viewTop = viewLocation[1] - rect.top;
DisplayMetrics metrics = new DisplayMetrics();
window.getWindowManager().getDefaultDisplay().getMetrics(metrics);
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(metrics.widthPixels, View.MeasureSpec.UNSPECIFIED);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(metrics.heightPixels, View.MeasureSpec.UNSPECIFIED);
toast.getView().measure(widthMeasureSpec, heightMeasureSpec);
int toastY = viewTop + view.getHeight();
toast.setGravity(Gravity.TOP | Gravity.CENTER_VERTICAL, 0, toastY);
toast.show();
}
示例5: showTutorial
import android.view.View; //导入方法依赖的package包/类
public void showTutorial(View view, CharSequence text, boolean isLast) {
this.isLast = isLast;
if (this.bitmap != null) {
this.bitmap.recycle();
}
if (this.lastTutorialView != null) {
this.lastTutorialView.setDrawingCacheEnabled(false);
}
final int[] location = new int[2];
this.lastTutorialView = view;
view.getLocationInWindow(location);
view.setDrawingCacheEnabled(true);
this.text.setText(text);
this.bitmap = view.getDrawingCache();
this.x = location[0];
this.y = location[1] - getStatusBarHeight();
this.setVisibility(View.VISIBLE);
moveText(!inTop());
postInvalidate();
}
示例6: isEventInVIew
import android.view.View; //导入方法依赖的package包/类
public static boolean isEventInVIew(final View view, final MotionEvent event) {
if (view != null) {
int[] leftTop = { 0, 0 };
//获取view当前的location位置
view.getLocationInWindow(leftTop);
int left = leftTop[0];
int top = leftTop[1];
int bottom = top + view.getHeight();
int right = left + view.getWidth();
if (event.getRawX() > left
&& event.getRawX() < right
&& event.getRawY() > top
&& event.getRawY() < bottom) {
return true;
} else {
return false;
}
}
return false;
}
示例7: gatherTransparentRegionsForOpaqueView
import android.view.View; //导入方法依赖的package包/类
/**
* Helper for overriding {@link ViewGroup#gatherTransparentRegion} for views that are fully
* opaque and have children extending beyond their bounds. If the transparent region
* optimization is turned on (which is the case whenever the view hierarchy contains a
* SurfaceView somewhere), the children might otherwise confuse the SurfaceFlinger.
*/
public static void gatherTransparentRegionsForOpaqueView(View view, Region region) {
view.getLocationInWindow(sLocationTmp);
region.op(sLocationTmp[0], sLocationTmp[1],
sLocationTmp[0] + view.getRight() - view.getLeft(),
sLocationTmp[1] + view.getBottom() - view.getTop(), Region.Op.DIFFERENCE);
}
示例8: isShouldHideKeyboard
import android.view.View; //导入方法依赖的package包/类
private boolean isShouldHideKeyboard(View v, MotionEvent event) {
if (v != null && (v instanceof EditText)) {
int[] l = {0, 0};
v.getLocationInWindow(l);
int left = l[0],
top = l[1],
bottom = top + v.getHeight(),
right = left + v.getWidth();
return !(event.getX() > left && event.getX() < right
&& event.getY() > top && event.getY() < bottom);
}
return false;
}
示例9: isShouldHideInput
import android.view.View; //导入方法依赖的package包/类
public boolean isShouldHideInput(View v, MotionEvent event) {
if (v != null && (v instanceof EditText)) {
int[] leftTop = {0, 0};
// 获取输入框当前的location位置
v.getLocationInWindow(leftTop);
int left = leftTop[0];
int top = leftTop[1];
int bottom = top + v.getHeight();
int right = left + v.getWidth();
return !(event.getX() > left && event.getX() < right
&& event.getY() > top && event.getY() < bottom);
}
return false;
}
示例10: updateLayoutParamsForPosiion
import android.view.View; //导入方法依赖的package包/类
private void updateLayoutParamsForPosiion(View anchor, WindowManager.LayoutParams p, int yOffset) {
DisplayMetrics displayMetrics = anchor.getResources().getDisplayMetrics();
screenSize.set(displayMetrics.widthPixels, displayMetrics.heightPixels);
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;
}
示例11: isShouldHideKeyboard
import android.view.View; //导入方法依赖的package包/类
/**
* 根据EditText所在坐标和用户点击的坐标相对比,来判断是否隐藏键盘
*/
private boolean isShouldHideKeyboard(View v, MotionEvent event) {
if (v != null && (v instanceof EditText)) {
int[] l = {0, 0};
v.getLocationInWindow(l);
int left = l[0],
top = l[1],
bottom = top + v.getHeight(),
right = left + v.getWidth();
return !(event.getX() > left && event.getX() < right
&& event.getY() > top && event.getY() < bottom);
}
return false;
}
示例12: testScrollAndClick
import android.view.View; //导入方法依赖的package包/类
public void testScrollAndClick() throws Exception {
SingleTouchGestureGenerator gestureGenerator = createGestureGenerator();
// Slowly drag the ScrollView to prevent fling
dragLeft(15000);
waitForBridgeAndUIIdle();
getInstrumentation().waitForIdleSync();
// Find visible item to be clicked
View visibleItem = null;
int visibleItemNumber = 0;
for (; visibleItemNumber < 100; visibleItemNumber++) {
visibleItem = getViewAtPath(0, 0, visibleItemNumber);
int pos[] = new int[2];
visibleItem.getLocationInWindow(pos);
if (pos[0] >= 0) {
break;
}
}
// Click first visible item
gestureGenerator.startGesture(visibleItem).endGesture();
waitForBridgeAndUIIdle();
ArrayList<Double> xOffsets = mScrollListenerModule.getXOffsets();
ArrayList<Integer> itemIds = mScrollListenerModule.getItemsPressed();
assertFalse("Expected to receive at least one scroll event", xOffsets.isEmpty());
assertTrue("Expected offset to be greater than 0", xOffsets.get(xOffsets.size() - 1) > 0);
assertEquals("Expected to receive exactly one item click event", 1, itemIds.size());
assertEquals(visibleItemNumber, (int) itemIds.get(0));
}
示例13: getRectangleCoordinates
import android.view.View; //导入方法依赖的package包/类
public Point getRectangleCoordinates(Tuple<Integer, Integer> tuple) {
Rect rect = boardSquares[tuple.first][tuple.last];
View rootLayout = getRootView().findViewById(android.R.id.content);
int[] viewLocation = new int[2];
int[] rootLocation = new int[2];
getLocationInWindow(viewLocation);
rootLayout.getLocationInWindow(rootLocation);
int relativeLeft = viewLocation[0] - rootLocation[0];
int relativeTop = viewLocation[1] - rootLocation[1];
int x = relativeLeft + rect.left;
int y = relativeTop + rect.top;
return new Point(x, y);
}
示例14: showMoreKeysPanel
import android.view.View; //导入方法依赖的package包/类
@Override
public void showMoreKeysPanel(final View parentView, final Controller controller,
final int pointX, final int pointY, final KeyboardActionListener listener) {
mController = controller;
mListener = listener;
final View container = getContainerView();
// The coordinates of panel's left-top corner in parentView's coordinate system.
// We need to consider background drawable paddings.
final int x = pointX - getDefaultCoordX() - container.getPaddingLeft() - getPaddingLeft();
final int y = pointY - container.getMeasuredHeight() + container.getPaddingBottom()
+ getPaddingBottom();
parentView.getLocationInWindow(mCoordinates);
// Ensure the horizontal position of the panel does not extend past the parentView edges.
final int maxX = parentView.getMeasuredWidth() - container.getMeasuredWidth();
final int panelX = Math.max(0, Math.min(maxX, x)) + CoordinateUtils.x(mCoordinates);
final int panelY = y + CoordinateUtils.y(mCoordinates);
container.setX(panelX);
container.setY(panelY);
mOriginX = x + container.getPaddingLeft();
mOriginY = y + container.getPaddingTop();
controller.onShowMoreKeysPanel(this);
final MoreKeysKeyboardAccessibilityDelegate accessibilityDelegate = mAccessibilityDelegate;
if (accessibilityDelegate != null
&& AccessibilityUtils.getInstance().isAccessibilityEnabled()) {
accessibilityDelegate.onShowMoreKeysKeyboard();
}
}
示例15: showOnAnchor
import android.view.View; //导入方法依赖的package包/类
/**
* Show at relative position to anchor View with translation.
* @param anchor Anchor View
* @param vertPos Vertical Position Flag
* @param horizPos Horizontal Position Flag
* @param x Translation X
* @param y Translation Y
* @param fitInScreen Automatically fit in screen or not
*/
public void showOnAnchor(@NonNull View anchor, @VerticalPosition int vertPos, @HorizontalPosition int horizPos, int x, int y, boolean fitInScreen) {
setClippingEnabled(fitInScreen);
View contentView = getContentView();
contentView.measure(makeDropDownMeasureSpec(getWidth()), makeDropDownMeasureSpec(getHeight()));
final int measuredW = contentView.getMeasuredWidth();
final int measuredH = contentView.getMeasuredHeight();
if (!fitInScreen) {
final int[] anchorLocation = new int[2];
anchor.getLocationInWindow(anchorLocation);
x += anchorLocation[0];
y += anchorLocation[1] + anchor.getHeight();
}
switch (vertPos) {
case VerticalPosition.ABOVE:
y -= measuredH + anchor.getHeight();
break;
case VerticalPosition.ALIGN_BOTTOM:
y -= measuredH;
break;
case VerticalPosition.CENTER:
y -= anchor.getHeight()/2 + measuredH/2;
break;
case VerticalPosition.ALIGN_TOP:
y -= anchor.getHeight();
break;
case VerticalPosition.BELOW:
// Default position.
break;
}
switch (horizPos) {
case HorizontalPosition.LEFT:
x -= measuredW;
break;
case HorizontalPosition.ALIGN_RIGHT:
x -= measuredW - anchor.getWidth();
break;
case HorizontalPosition.CENTER:
x += anchor.getWidth()/2 - measuredW/2;
break;
case HorizontalPosition.ALIGN_LEFT:
// Default position.
break;
case HorizontalPosition.RIGHT:
x += anchor.getWidth();
break;
}
if (fitInScreen) {
PopupWindowCompat.showAsDropDown(this, anchor, x, y, Gravity.NO_GRAVITY);
} else {
showAtLocation(anchor, Gravity.NO_GRAVITY, x, y);
}
}