当前位置: 首页>>代码示例>>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;未经允许,请勿转载。