当前位置: 首页>>代码示例>>Java>>正文


Java View.getLocationInWindow方法代码示例

本文整理汇总了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);
}
 
开发者ID:rkkr,项目名称:simple-keyboard,代码行数:25,代码来源:MoreKeysKeyboardView.java

示例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();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:PopupWindowProxy.java

示例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;
}
 
开发者ID:Wilshion,项目名称:HeadlineNews,代码行数:20,代码来源:BaseActivity.java

示例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();
}
 
开发者ID:mobilemaster128,项目名称:quickblox-android,代码行数:23,代码来源:Toaster.java

示例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();
}
 
开发者ID:Popalay,项目名称:Tutors,代码行数:25,代码来源:TutorialLayout.java

示例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;
}
 
开发者ID:Lingzh0ng,项目名称:BrotherWeather,代码行数:21,代码来源:AppUtils.java

示例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);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:13,代码来源:ViewUtils.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:KeyboardActivity.java

示例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;
}
 
开发者ID:fendoudebb,项目名称:PlayAndroid,代码行数:15,代码来源:BaseActivity.java

示例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;
}
 
开发者ID:zacharee,项目名称:SliderPreferenceEmbedded,代码行数:14,代码来源:PopupIndicator.java

示例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;
}
 
开发者ID:zengcanxiang,项目名称:MVP-Practice-Project-Template,代码行数:17,代码来源:MVPBaseActivity.java

示例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));
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:33,代码来源:ReactHorizontalScrollViewTestCase.java

示例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);
}
 
开发者ID:android-gamecollection,项目名称:gamecollection,代码行数:16,代码来源:CheckeredGameboardView.java

示例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();
    }
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:30,代码来源:MoreKeysKeyboardView.java

示例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);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:62,代码来源:RelativePopupWindow.java


注:本文中的android.view.View.getLocationInWindow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。