當前位置: 首頁>>代碼示例>>Java>>正文


Java View.getLocationOnScreen方法代碼示例

本文整理匯總了Java中android.view.View.getLocationOnScreen方法的典型用法代碼示例。如果您正苦於以下問題:Java View.getLocationOnScreen方法的具體用法?Java View.getLocationOnScreen怎麽用?Java View.getLocationOnScreen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.View的用法示例。


在下文中一共展示了View.getLocationOnScreen方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: showAccessibilityToast

import android.view.View; //導入方法依賴的package包/類
/**
 * Shows the content description toast for items on the toolbar.
 * @param view The view to anchor the toast.
 * @param description The string shown in the toast.
 * @return Whether a toast has been shown successfully.
 */
protected boolean showAccessibilityToast(View view, CharSequence description) {
    if (description == null) return false;

    final int screenWidth = getResources().getDisplayMetrics().widthPixels;
    final int[] screenPos = new int[2];
    view.getLocationOnScreen(screenPos);
    final int width = view.getWidth();

    Toast toast = Toast.makeText(getContext(), description, Toast.LENGTH_SHORT);
    toast.setGravity(
            Gravity.TOP | Gravity.END,
            screenWidth - screenPos[0] - width / 2,
            screenPos[1] + getHeight() / 2);
    toast.show();
    return true;
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:23,代碼來源:ToolbarLayout.java

示例2: calcuateOffset

import android.view.View; //導入方法依賴的package包/類
/**
 * 計算popupwindow的偏移量
 *
 * @param anchorView
 * @return
 * @see #showPopupWindow(View)
 */
private int[] calcuateOffset(View anchorView) {
    int[] offset = {offsetX, offsetY};
    anchorView.getLocationOnScreen(mAnchorViewLocation);
    if (isAutoLocatePopup) {
        final boolean onTop = (getScreenHeight() - (mAnchorViewLocation[1] + offset[1]) < getHeight());
        if (onTop) {
            offset[1] = -anchorView.getHeight() - getHeight() - offset[1];
            showOnTop(mPopupView);
        } else {
            showOnDown(mPopupView);
        }
    }
    return offset;

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:BasePopupWindow.java

示例3: onNestedPreScroll

import android.view.View; //導入方法依賴的package包/類
@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child,
        View target, int dx, int dy, int[] consumed, int type) {
    if (this.toolbar == null) {
        this.toolbar = findToolbar(child);
        if (this.toolbar == null) {
            return;
        }
    }
    int[] toolbarLocation = new int[2];
    toolbar.getLocationOnScreen(toolbarLocation);
    int[] targetLocation = new int[2];
    target.getLocationOnScreen(targetLocation);
    int toolbarBottomY = toolbarLocation[1] + toolbar.getHeight();
    int[] appbarLocation = new int[2];
    int nestedScrollViewTopY = targetLocation[1];
    child.getLocationOnScreen(appbarLocation);
    NestedWebView nestedWebView = (NestedWebView) target;
    if (nestedScrollViewTopY <= toolbarBottomY) {
        nestedWebView.onChangeCollapseToolbar(true, dy);
    } else {
        nestedWebView.onChangeCollapseToolbar(false, dy);
    }
    super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type);
}
 
開發者ID:marshi,項目名稱:NestedWebView,代碼行數:26,代碼來源:NestedWebViewAppBarLayout.java

示例4: startSecondFragment

import android.view.View; //導入方法依賴的package包/類
private void startSecondFragment(int type, View view) {
  SharedTargetFragment fragment = SharedTargetFragment.newInstance(type);
  Bundle bundle = fragment.getArguments();
  int[] screenLocation = new int[2];
  view.getLocationOnScreen(screenLocation);
  bundle.putIntArray(BUNDLE_KEY + 1, screenLocation);
  bundle.putIntArray(BUNDLE_KEY + 2, new int[]{view.getWidth(), view.getHeight()});
  switch (type) {
    case TYPE_HAMMER:
      break;
    case TYPE_HOURGLASS:
      break;
    case TYPE_SEND:
      break;
    case TYPE_CLOUD:
      break;
  }
  Rigger.getRigger(this).startFragment(fragment);
}
 
開發者ID:JustKiddingBaby,項目名稱:FragmentRigger,代碼行數:20,代碼來源:SharedElementFragment.java

示例5: getClickOrigin

import android.view.View; //導入方法依賴的package包/類
private Pair<Integer, Integer> getClickOrigin(@Nullable View anchor, @NonNull View contentView) {
  if (anchor == null) return new Pair<>(0, 0);

  final int[] anchorCoordinates = new int[2];
  anchor.getLocationOnScreen(anchorCoordinates);
  anchorCoordinates[0] += anchor.getWidth() / 2;
  anchorCoordinates[1] += anchor.getHeight() / 2;

  final int[] contentCoordinates = new int[2];
  contentView.getLocationOnScreen(contentCoordinates);

  int x = anchorCoordinates[0] - contentCoordinates[0];
  int y = anchorCoordinates[1] - contentCoordinates[1];

  return new Pair<>(x, y);
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:17,代碼來源:AttachmentTypeSelector.java

示例6: AnimatorFactory

import android.view.View; //導入方法依賴的package包/類
AnimatorFactory(View startView) {
    final int width = startView.getWidth();
    final int height = startView.getHeight();
    startRadius = Math.min(width, height) / 2;

    int[] location = new int[2];
    startView.getLocationOnScreen(location);
    x = location[0] + width / 2;
    y = location[1] + height / 2;
}
 
開發者ID:roshakorost,項目名稱:Phial,代碼行數:11,代碼來源:AnimatorFactory.java

示例7: showUpPop

import android.view.View; //導入方法依賴的package包/類
public void showUpPop(View view) {
        if (popupWindow != null && popupWindow.isShowing()) return;
        popupWindow = new MyCommonPopularWindow.Builder(this)
                .setView(R.layout.layout_popular_2)
                .setWidthAndHeight(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
                .create();
//        popupWindow.showAsDropDown(view, 0, -(popupWindow.getHeight() + view.getMeasuredHeight()));

        int[] location = new int[2];
        view.getLocationOnScreen(location);
        popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, location[0], location[1]-popupWindow.getHeight());
    }
 
開發者ID:songjiabin,項目名稱:MySelfDemo,代碼行數:13,代碼來源:MyDemoActivity.java

示例8: captureScreenLocationValues

import android.view.View; //導入方法依賴的package包/類
private static void captureScreenLocationValues(@NonNull Bundle b, @NonNull View view) {
  if (view instanceof ImageView) {
    int[] size = ImageViewUtil.getDisplayedImageLocation((ImageView) view);
    b.putInt(PROPNAME_SCREENLOCATION_LEFT, size[0]);
    b.putInt(PROPNAME_SCREENLOCATION_TOP, size[1]);
  } else {
    int[] screenLocation = new int[2];
    view.getLocationOnScreen(screenLocation);
    b.putInt(PROPNAME_SCREENLOCATION_LEFT, screenLocation[0]);
    b.putInt(PROPNAME_SCREENLOCATION_TOP, screenLocation[1]);
  }
}
 
開發者ID:JustKiddingBaby,項目名稱:FragmentRigger,代碼行數:13,代碼來源:SharedTargetFragment.java

示例9: updateTempLocation

import android.view.View; //導入方法依賴的package包/類
private void updateTempLocation(View view)
{
    if (view == null)
    {
        return;
    }
    if (mTempLocation == null)
    {
        mTempLocation = new int[]{0, 0};
    }
    view.getLocationOnScreen(mTempLocation);
}
 
開發者ID:zj565061763,項目名稱:animator,代碼行數:13,代碼來源:FAnimator.java

示例10: isOnRange

import android.view.View; //導入方法依賴的package包/類
private boolean isOnRange(MotionEvent e, View childView) {
//                        LogUtil.e("更改" + mPressedView.getTop());
//                        LogUtil.e("1點的位置x:" + e.getRawX() + "    y:" + e.getRawY());
//                        int newLeft = childView.getLeft() + mPressedView.getLeft();
//                        int newRight = childView.getRight() + mPressedView.getLeft();
//                        int newTop = childView.getTop() + mPressedView.getTop();
//                        int newBottom = childView.getBottom() + mPressedView.getTop();
//                        LogUtil.e("newLeft:" + newLeft + "    newRight:" + newRight);
//                        LogUtil.e("newTop:" + newTop + "     newBottom" + newBottom);
//                        if ((newLeft <= e.getRawX() && e.getRawX() <= newRight) &&
//                                (newTop <= e.getRawY() && e.getRawY() <= newBottom)) {
//                                return true;
//                        } else {
//                                return false;
//                        }


                        int[] location = new int[2];
                        childView.getLocationOnScreen(location);
//                        LogUtil.e("scrollX" + childView.getScrollX() + "     scrollY" + childView.getScrollY());
                        LogUtil.e("1view點的位置x:" + location[0] + "    y:" + location[1]);
                        LogUtil.e("1點的位置x:" + e.getRawX() + "    y:" + e.getRawY());
                        LogUtil.e("1view的大小w:" + childView.getWidth() + "    h:" + childView.getHeight());

                        if ((location[0] < e.getRawX() && e.getRawX() < location[0] + childView.getWidth()) &&
                                (location[1] < e.getRawY() && e.getRawY() < location[1] + childView.getHeight())) {
                                LogUtil.e("true");
                                return true;
                        }
                        LogUtil.e("false");
                        return false;
                }
 
開發者ID:HelloChenJinJun,項目名稱:TestChat,代碼行數:33,代碼來源:BaseItemClickListener.java

示例11: isCancelled

import android.view.View; //導入方法依賴的package包/類
private boolean isCancelled(View view, MotionEvent event) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);

    if (event.getRawX() < location[0] || event.getRawX() > location[0] + view.getWidth()
            || event.getRawY() < location[1] - 40) {
        return true;
    }

    return false;
}
 
開發者ID:GitLqr,項目名稱:LQRWeChat,代碼行數:12,代碼來源:SessionActivity.java

示例12: isEventWithinView

import android.view.View; //導入方法依賴的package包/類
private boolean isEventWithinView(MotionEvent e, View child) {
    Rect viewRect = new Rect();
    int[] childPosition = new int[2];
    child.getLocationOnScreen(childPosition);
    int left = childPosition[0];
    int right = left + child.getWidth();
    int top = childPosition[1];
    int bottom = top + child.getHeight();
    viewRect.set(left, top, right, bottom);
    return viewRect.contains((int) e.getRawX(), (int) e.getRawY());
}
 
開發者ID:abook23,項目名稱:godlibrary,代碼行數:12,代碼來源:HorizontalListView.java

示例13: onTouchEvent

import android.view.View; //導入方法依賴的package包/類
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
    View root = getRootView();
    if (root == null || !(root instanceof ViewGroup)) {
        return false;
    }
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            root.getLocationOnScreen(p);
            scrollParent = getScrollParent();
            if (scrollParent != null) {
                scrollParent.requestDisallowInterceptTouchEvent(true);
            }
            int location[] = new int[2];
            getLocationOnScreen(location);
            x = location[0] + (getWidth() / 2) - p[0];
            y = location[1] + (getHeight() / 2) - p[1];
            r = (getWidth() + getHeight()) / 4;
            pointView = new PointView(getContext());
            pointView.setLayoutParams(new ViewGroup.LayoutParams(root.getWidth(), root.getHeight()));
            setDrawingCacheEnabled(true);
            pointView.catchBitmap = getDrawingCache();
            pointView.setLocation(x, y, r, event.getRawX() - p[0], event.getRawY() - p[1]);
            ((ViewGroup) root).addView(pointView);
            setVisibility(View.INVISIBLE);
            break;
        case MotionEvent.ACTION_MOVE:
            pointView.refrashXY(event.getRawX() - p[0], event.getRawY() - p[1]);
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            if (scrollParent != null) {
                scrollParent.requestDisallowInterceptTouchEvent(false);
            }
            if (!pointView.broken) { // 沒有拉斷
                pointView.cancel();
            } else if (pointView.nearby) {// 拉斷了,但是又回去了
                pointView.cancel();
            } else { // 徹底拉斷了
                pointView.broken();
            }
            break;
        default:
            break;
    }
    return true;
}
 
開發者ID:zqHero,項目名稱:rongyunDemo,代碼行數:49,代碼來源:DragPointView.java

示例14: getCenterX

import android.view.View; //導入方法依賴的package包/類
private int getCenterX(View view) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);
    return location[0] + view.getWidth() / 2;
}
 
開發者ID:sega4revenge,項目名稱:Sega,代碼行數:6,代碼來源:SearchView.java

示例15: show

import android.view.View; //導入方法依賴的package包/類
void show(@NonNull final View clickedImage, @NonNull final Emoji emoji) {
    dismiss();

    final View content = View.inflate(clickedImage.getContext(), R.layout.emoji_skin_popup, null);
    final LinearLayout imageContainer = (LinearLayout) content.findViewById(R.id.container);

    popupWindow = new PopupWindow(content,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT
    );

    final List<Emoji> variants = emoji.getBase().getVariants();
    variants.add(0, emoji.getBase());

    final LayoutInflater inflater = LayoutInflater.from(clickedImage.getContext());

    for (final Emoji variant : variants) {
        final ImageView emojiImage = (ImageView) inflater.inflate(R.layout.emoji_item, imageContainer, false);
        final ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) emojiImage.getLayoutParams();
        final int margin = Utils.dpToPx(clickedImage.getContext(), MARGIN);

        // Use the same size for Emojis as in the picker.
        layoutParams.width = clickedImage.getWidth();
        layoutParams.setMargins(margin, margin, margin, margin);
        emojiImage.setImageResource(variant.getResource());

        emojiImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View view) {
                if (listener != null) {
                    listener.onEmojiClicked(variant);
                }
            }
        });

        imageContainer.addView(emojiImage);
    }

    content.measure(makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));

    popupWindow.setOutsideTouchable(true);
    popupWindow.setBackgroundDrawable(new BitmapDrawable(clickedImage.getContext().getResources(), (Bitmap) null));

    final int[] location = new int[2];
    clickedImage.getLocationOnScreen(location);

    final int x = location[0] - popupWindow.getContentView().getMeasuredWidth() / 2 + clickedImage.getWidth() / 2;
    final int y = location[1] - popupWindow.getContentView().getMeasuredHeight();

    popupWindow.showAtLocation(((Activity) content.getContext()).getWindow().getDecorView(),
            Gravity.NO_GRAVITY, x, y);
}
 
開發者ID:apradanas,項目名稱:prismoji-android,代碼行數:53,代碼來源:PrismojiVariantPopup.java


注:本文中的android.view.View.getLocationOnScreen方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。