???????????е?????λ??????????????????п????????????Σ??????????????????????????λ???????

?????????????????????????????????????????dpi?????С???????????????????????????????????????

1:  // ???????????????View?????
2:  public void clickOnScreen(View view?? boolean longClick?? int time) {
3:      if(view == null)
4:          Assert.assertTrue("View is null and can therefore not be clicked!"?? false);
5:      int[] xy = new int[2];
6:
7:  // ??????????????λ?? – ?????dpi?????С?????????λ??????????λ??
8:      view.getLocationOnScreen(xy);
9:
10:  // ?????????С??????????????????е?λ??
11:      final int top = view.getTop();
12:      final int viewWidth = view.getWidth();
13:      final int viewHeight = view.getHeight();
14:      float x = xy[0] + (viewWidth / 2.0f);
15:      float y = xy[1] + (viewHeight / 2.0f);
16:
17:  // ?????????????????????x?? y????????????????????
18:      Activity activity = activityUtils.getCurrentActivity();
19:      DisplayMetrics rdm = activity.getResources().getDisplayMetrics();
20:      DisplayMetrics wdm = new DisplayMetrics();
21:      activity.getWindowManager().getDefaultDisplay().getMetrics(wdm);
22:      x *= wdm.scaledDensity / rdm.scaledDensity;
23:      y *= wdm.scaledDensity / rdm.scaledDensity;
24:
25:  // ???????Android??????
26:      if (longClick)
27:          clickLongOnScreen(x?? y?? time);
28:      else
29:          clickOnScreen(x?? y);
30:  }