public final boolean getGlobalVisibleRect(Rect r) public boolean getGlobalVisibleRect(Rect r, Point globalOffset)  public final boolean getLocalVisibleRect(Rect r)  public void getLocationInWindow(int[] location) public void getLocationOnScreen(int[] location)  public void getWindowVisibleDisplayFrame(Rect outRect)  getLeft()、getTop()、getRight()、getBottom() getX()、getY() getTranslationX()、getTranslationY() getScrollX()、getScrollY()

首先明白Android 全局坐标系和相对坐标系
全局坐标系是整个手机屏幕,相对坐标系是某个View自己的小坐标系

先看结论:

getGlobalVisibleRect(Rect r)

     Global表示全局,Visible表示可见,意思就是,计算一个View在全局 坐标系里的可见区域的矩形位置

getGlobalVisibleRect(Rect r, Point globalOffset)

    和getGlobalVisibleRect(Rect r)是一样的但是有一个Point 参数,记录的是View的左上顶点在全局坐标系的里点位置

getLocalVisibleRect(Rect r)

    以View自己为坐标系计算自己的可见矩形区域坐标

getLocationInWindow(int[] location)和getLocationOnScreen(int[] location)

    这两个及其相似,Android里的顶层View是PhoneWindow,里面有个DecorView,InWindow的含义就是以这个PhoneWindow为坐标系,location的数组长度为2,表示View的左上顶点的x、y坐标。OnScreen表示整个屏幕(全局坐标)当我们在Activity中使用时,它们两个的值是一样的,但是当我们在Dialog里使用时,就不一样了,Dialog有自己的DecorView与Activity的DecorView不是一个对象。

getWindowVisibleDisplayFrame(Rect outRect)

    得到窗口的可视区域,不包含状态栏。就是内容区+标题栏

getLeft()、getTop()、getRight()、getBottom()

    以当前view的父View为坐标系,getLeft()、getTop()左上顶点的坐标,getRight()、getBottom()右下顶点的坐标。

getX()、getY()

    相对父容器,左上角的坐标,如果父容器发生滚动ScrollX、ScrollY,对getX( )与getY( )没有影响。
如果view没有移动,getX()、getY()可能会与getLeft()、getTop()相同。
但是但我们直接调用setX( )、setY( )时,getLeft()、getTop()系列的值并没有改变。

getTranslationX()、getTranslationY()

在父容器里的位移,负值是向左或向上。正值向右或向下

getScrollX()、getScrollY()

发生滚动表示view里的内容发生滚动,正值表示内容向左或向上滚动
,负值表示内容向右或向下滚动。滚动的值没有影响子view的坐标位置

实例

                                                                         

Dialog的布局和上面的一样,只是没有按钮

public class MainActivity extends AppCompatActivity implements OnClickListener {    private final static String TAG = "viewloaction";    View view1,view2,view3,view4,view5,view6,view7,view8;    RelativeLayout viewContainer,viewContainer2;    Button btnDialog;    int lastX = 0;    int lastY = 0;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        view1 = findViewById(R.id.view1);        view2 = findViewById(R.id.view2);        view3 = findViewById(R.id.view3);        view3.setOnTouchListener(new OnTouchListener() {            @Override            public boolean onTouch(View v, MotionEvent event) {                int action = event.getAction();                switch (action) {                case MotionEvent.ACTION_DOWN:                    lastX = (int) event.getRawX();                    lastY = (int) event.getRawY();                    break;                case MotionEvent.ACTION_MOVE:                int dx = (int) (event.getRawX() - lastX);                int dy = (int) (event.getRawY() - lastY);                lastX = (int) event.getRawX();                lastY = (int) event.getRawY();                view3.setX(view3.getX()+dx);                view3.setY(view3.getY()+dy);                if(view3.getX()<0) view3.setX(0);                if(view3.getX()>((View)view3.getParent()).getWidth()-view3.getWidth()) view3.setX(((View)view3.getParent()).getWidth()-view3.getWidth());                if(view3.getY()<0)view3.setY(0);                if(view3.getY()>((View)view3.getParent()).getHeight()-view3.getHeight()) view3.setY(((View)view3.getParent()).getHeight()-view3.getHeight());                    break;                case MotionEvent.ACTION_UP:                       viewLocation(view3, "view3");                    break;                default:                    break;                }                return true;            }        });        viewContainer = (RelativeLayout) findViewById(R.id.viewContainer);            viewContainer2 = (RelativeLayout) findViewById(R.id.viewContainer2);        view4 = findViewById(R.id.view4);        view5 = findViewById(R.id.view5);        view6 = findViewById(R.id.view6);        view7 = findViewById(R.id.view7);        view8 = findViewById(R.id.view8);        btnDialog = (Button) findViewById(R.id.btnDialog);        btnDialog.setOnClickListener(this);        //屏幕的真实尺寸        WindowManager mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);          Display mDisplay = mWindowManager.getDefaultDisplay();          DisplayMetrics mDisplayMetrics = new DisplayMetrics();          mDisplay.getRealMetrics(mDisplayMetrics);          int realScreenW = mDisplayMetrics.widthPixels;        int realScreenH = mDisplayMetrics.heightPixels;        Log.i(TAG, "RealMetrics "+"w = "+ realScreenW+"  h = "+realScreenH);        //屏幕尺寸,可能和屏幕的真实尺寸一样        mDisplay.getMetrics(mDisplayMetrics);        int screenW = mDisplayMetrics.widthPixels;        int screenH = mDisplayMetrics.heightPixels;        Log.i(TAG, "Metrics "+"density = " +mDisplayMetrics.density);        Log.i(TAG, "Metrics "+"densityDpi = " +mDisplayMetrics.densityDpi);        Log.i(TAG, "Metrics "+"w = "+ screenW+"  h = "+screenH);        Log.i(TAG, "底部动作条(Bottom Sheets) "+"  h = "+(realScreenH - screenH));        viewContainer.post(new Runnable() {            public void run() {                //状态栏的高度                Log.i(TAG, "状态栏的高度 = " + getStatusBarHeight());                  //标题栏的高度                Log.i(TAG, "标题栏的高度 = " + getTitleBarHeight());                  viewLocation(view1, "view1");                viewLocation(view2, "view2");                viewLocation(view3, "view3");                viewLocation(viewContainer, "viewContainer");                viewLocation(viewContainer2, "viewContainer2");                viewLocation(view4, "view4");                viewLocation(view5, "view5");                viewLocation(view6, "view6");                viewLocation(view7, "view7");                viewLocation(view8, "view8");            }        });    }    private void viewLocation(View view,String viewName) {        Rect rect = new Rect() ;        view.getGlobalVisibleRect(rect);        Log.i(TAG, viewName+"--getGlobalVisibleRect(rect)>>"+rect);        Point point = new Point();        view.getGlobalVisibleRect(rect, point);        Log.i(TAG, viewName+"--getGlobalVisibleRect(rect, point)>>"        +rect        +"point>>"+"("+point.x+","+point.y+")" );        view.getLocalVisibleRect(rect);        Log.i(TAG, viewName+"--getLocalVisibleRect(rect)>>"+rect);        int[] locationInWindow = new int[2];        view.getLocationInWindow(locationInWindow);        Log.i(TAG, viewName+"--getLocationInWindow(location)>>"+"("+locationInWindow[0]+","+locationInWindow[1]+")");        int[] locationOnScreen = new int[2];        view.getLocationOnScreen(locationOnScreen);        Log.i(TAG, viewName+"--getLocationOnScreen(location)>>"+"("+locationOnScreen[0]+","+locationOnScreen[1]+")");        view.getWindowVisibleDisplayFrame(rect);        Log.i(TAG, viewName+"--getWindowVisibleDisplayFrame(rect)>>"+rect);        Log.i(TAG, viewName+"--getLeft()="+view.getLeft()+" getTop()="+view.getTop()+" getRight()="+view.getRight()+" getBottom()="+view.getBottom());Log.i(TAG, viewName+"--getX()="+view.getX()+"      getY()="+view.getY());        Log.i(TAG, viewName+"--getTranslationX()="+view.getTranslationX()+"  getTranslationY()="+view.getTranslationY());        Log.i(TAG, viewName+"--getTranslationX()="+view.getTranslationX()+"  getTranslationY()="+view.getTranslationY());        Log.i(TAG, viewName+"--getScrollX()="+view.getScrollX()+"  getScrollY()="+view.getScrollY());           Log.i(TAG, "-------------------------------------------");     }     private int getStatusBarHeight() {          //方法一//      Resources resources = getResources();  //      int resourceId = resources.getIdentifier("status_bar_height", "dimen","android");  //      int statusBarHeight = resources.getDimensionPixelSize(resourceId);         //方法二,注意要等到窗口加载好后调用        Rect frame = new Rect();          getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);          int statusBarHeight = frame.top; //状态栏高度         return statusBarHeight;      }     private int getTitleBarHeight(){        int titleBarHeight = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();          return titleBarHeight;    }    public void onClick(View v) {        final Dialog dialog = new Dialog(this);        final View view = getLayoutInflater().inflate(R.layout.activity_dialog, null,false);        dialog.addContentView(view, new LayoutParams(                  LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));        dialog.setOnShowListener(new OnShowListener() {            public void onShow(DialogInterface dialo) {                Log.i(TAG, "######################################");                View dialogDecorView = dialog.getWindow().getDecorView();                View activityDecorView = getWindow().getDecorView();                Log.i(TAG, "dialogDecorView ==activityDecorView >>"+(activityDecorView==dialogDecorView ));//              View peekDecor = dialog.getWindow().peekDecorView();                dialogDecorView.setBackground(new ColorDrawable(Color.parseColor("#81d4fa")));//              peekDecor.setBackground(new ColorDrawable(Color.rgb(0, 255, 0)));                viewLocation(dialogDecorView, "dialogView");                dialogLocation(dialogDecorView, "dialog");            }        });        dialog.show();    }    private void dialogLocation(View view,String name){        for(int i = 0,len =((ViewGroup)view).getChildCount();i0){                dialogLocation(childView,name+i+"--");            }        }    }}
 RealMetrics w = 1200  h = 1920 Metrics density = 2.0 Metrics densityDpi = 320 Metrics w = 1200  h = 1824 底部动作条(Bottom Sheets)   h = 96 状态栏的高度 = 50 标题栏的高度 = 128 view1--getGlobalVisibleRect(rect)>>Rect(0, 198 - 100, 398) view1--getGlobalVisibleRect(rect, point)>>Rect(0, 198 - 100, 398)point>>(-99,198) view1--getLocalVisibleRect(rect)>>Rect(99, 0 - 199, 200) view1--getLocationInWindow(location)>>(-99,198) view1--getLocationOnScreen(location)>>(-99,198) view1--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) view1--getLeft()=0 getTop()=20 getRight()=200 getBottom()=220 view1--getX()=-100.0      getY()=20.0 view1--getTranslationX()=-100.0  getTranslationY()=0.0 view1--getTranslationX()=-100.0  getTranslationY()=0.0 view1--getScrollX()=0  getScrollY()=0 ------------------------------------------- view2--getGlobalVisibleRect(rect)>>Rect(500, 198 - 700, 398) view2--getGlobalVisibleRect(rect, point)>>Rect(500, 198 - 700, 398)point>>(500,198) view2--getLocalVisibleRect(rect)>>Rect(0, 0 - 200, 200) view2--getLocationInWindow(location)>>(500,198) view2--getLocationOnScreen(location)>>(500,198) view2--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) view2--getLeft()=500 getTop()=20 getRight()=700 getBottom()=220 view2--getX()=500.0      getY()=20.0 view2--getTranslationX()=0.0  getTranslationY()=0.0 view2--getTranslationX()=0.0  getTranslationY()=0.0 view2--getScrollX()=0  getScrollY()=0 ------------------------------------------- view3--getGlobalVisibleRect(rect)>>Rect(1100, 198 - 1200, 398) view3--getGlobalVisibleRect(rect, point)>>Rect(1100, 198 - 1200, 398)point>>(1100,198) view3--getLocalVisibleRect(rect)>>Rect(0, 0 - 100, 200) view3--getLocationInWindow(location)>>(1100,198) view3--getLocationOnScreen(location)>>(1100,198) view3--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) view3--getLeft()=1000 getTop()=20 getRight()=1200 getBottom()=220 view3--getX()=1100.0      getY()=20.0 view3--getTranslationX()=100.0  getTranslationY()=0.0 view3--getTranslationX()=100.0  getTranslationY()=0.0 view3--getScrollX()=0  getScrollY()=0 ------------------------------------------- viewContainer--getGlobalVisibleRect(rect)>>Rect(300, 458 - 900, 1058) viewContainer--getGlobalVisibleRect(rect, point)>>Rect(300, 458 - 900, 1058)point>>(300,458) viewContainer--getLocalVisibleRect(rect)>>Rect(0, 0 - 600, 600) viewContainer--getLocationInWindow(location)>>(300,458) viewContainer--getLocationOnScreen(location)>>(300,458) viewContainer--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) viewContainer--getLeft()=300 getTop()=280 getRight()=900 getBottom()=880 viewContainer--getX()=300.0      getY()=280.0 viewContainer--getTranslationX()=0.0  getTranslationY()=0.0 viewContainer--getTranslationX()=0.0  getTranslationY()=0.0 viewContainer--getScrollX()=0  getScrollY()=0 ------------------------------------------- viewContainer2--getGlobalVisibleRect(rect)>>Rect(300, 1338 - 900, 1538) viewContainer2--getGlobalVisibleRect(rect, point)>>Rect(300, 1338 - 900, 1538)point>>(200,1238) viewContainer2--getLocalVisibleRect(rect)>>Rect(100, 100 - 700, 300) viewContainer2--getLocationInWindow(location)>>(300,1338) viewContainer2--getLocationOnScreen(location)>>(300,1338) viewContainer2--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) viewContainer2--getLeft()=300 getTop()=1160 getRight()=900 getBottom()=1360 viewContainer2--getX()=300.0      getY()=1160.0 viewContainer2--getTranslationX()=0.0  getTranslationY()=0.0 viewContainer2--getTranslationX()=0.0  getTranslationY()=0.0 viewContainer2--getScrollX()=100  getScrollY()=100 ------------------------------------------- view4--getGlobalVisibleRect(rect)>>Rect(300, 458 - 400, 658) view4--getGlobalVisibleRect(rect, point)>>Rect(300, 458 - 400, 658)point>>(201,458) view4--getLocalVisibleRect(rect)>>Rect(99, 0 - 199, 200) view4--getLocationInWindow(location)>>(200,458) view4--getLocationOnScreen(location)>>(200,458) view4--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) view4--getLeft()=0 getTop()=0 getRight()=200 getBottom()=200 view4--getX()=-100.0      getY()=0.0 view4--getTranslationX()=-100.0  getTranslationY()=0.0 view4--getTranslationX()=-100.0  getTranslationY()=0.0 view4--getScrollX()=0  getScrollY()=0 ------------------------------------------- view5--getGlobalVisibleRect(rect)>>Rect(500, 458 - 700, 658) view5--getGlobalVisibleRect(rect, point)>>Rect(500, 458 - 700, 658)point>>(500,458) view5--getLocalVisibleRect(rect)>>Rect(0, 0 - 200, 200) view5--getLocationInWindow(location)>>(500,458) view5--getLocationOnScreen(location)>>(500,458) view5--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) view5--getLeft()=200 getTop()=0 getRight()=400 getBottom()=200 view5--getX()=200.0      getY()=0.0 view5--getTranslationX()=0.0  getTranslationY()=0.0 view5--getTranslationX()=0.0  getTranslationY()=0.0 view5--getScrollX()=0  getScrollY()=0 ------------------------------------------- view6--getGlobalVisibleRect(rect)>>Rect(800, 458 - 900, 658) view6--getGlobalVisibleRect(rect, point)>>Rect(800, 458 - 900, 658)point>>(800,458) view6--getLocalVisibleRect(rect)>>Rect(0, 0 - 100, 200) view6--getLocationInWindow(location)>>(800,458) view6--getLocationOnScreen(location)>>(800,458) view6--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) view6--getLeft()=400 getTop()=0 getRight()=600 getBottom()=200 view6--getX()=500.0      getY()=0.0 view6--getTranslationX()=100.0  getTranslationY()=0.0 view6--getTranslationX()=100.0  getTranslationY()=0.0 view6--getScrollX()=0  getScrollY()=0 ------------------------------------------- view7--getGlobalVisibleRect(rect)>>Rect(500, 658 - 700, 858) view7--getGlobalVisibleRect(rect, point)>>Rect(500, 658 - 700, 858)point>>(500,658) view7--getLocalVisibleRect(rect)>>Rect(0, 0 - 200, 200) view7--getLocationInWindow(location)>>(500,658) view7--getLocationOnScreen(location)>>(500,658) view7--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) view7--getLeft()=200 getTop()=200 getRight()=400 getBottom()=400 view7--getX()=200.0      getY()=200.0 view7--getTranslationX()=0.0  getTranslationY()=0.0 view7--getTranslationX()=0.0  getTranslationY()=0.0 view7--getScrollX()=0  getScrollY()=0 ------------------------------------------- view8--getGlobalVisibleRect(rect)>>Rect(300, 1338 - 800, 1438) view8--getGlobalVisibleRect(rect, point)>>Rect(300, 1338 - 800, 1438)point>>(200,1238) view8--getLocalVisibleRect(rect)>>Rect(100, 100 - 600, 200) view8--getLocationInWindow(location)>>(200,1238) view8--getLocationOnScreen(location)>>(200,1238) view8--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) view8--getLeft()=0 getTop()=0 getRight()=600 getBottom()=200 view8--getX()=0.0      getY()=0.0 view8--getTranslationX()=0.0  getTranslationY()=0.0 view8--getTranslationX()=0.0  getTranslationY()=0.0 view8--getScrollX()=0  getScrollY()=0 ------------------------------------------- ###################################### dialogDecorView ==activityDecorView >>false dialogView--getGlobalVisibleRect(rect)>>Rect(0, 0 - 1160, 1044) dialogView--getGlobalVisibleRect(rect, point)>>Rect(0, 0 - 1160, 1044)point>>(0,0) dialogView--getLocalVisibleRect(rect)>>Rect(0, 0 - 1160, 1044) dialogView--getLocationInWindow(location)>>(0,0) dialogView--getLocationOnScreen(location)>>(20,415) dialogView--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) dialogView--getLeft()=0 getTop()=0 getRight()=1160 getBottom()=1044 dialogView--getX()=0.0      getY()=0.0 dialogView--getTranslationX()=0.0  getTranslationY()=0.0 dialogView--getTranslationX()=0.0  getTranslationY()=0.0 dialogView--getScrollX()=0  getScrollY()=0 ------------------------------------------- dialog0--getGlobalVisibleRect(rect)>>Rect(16, 16 - 1144, 1028) dialog0--getGlobalVisibleRect(rect, point)>>Rect(16, 16 - 1144, 1028)point>>(16,16) dialog0--getLocalVisibleRect(rect)>>Rect(0, 0 - 1128, 1012) dialog0--getLocationInWindow(location)>>(16,16) dialog0--getLocationOnScreen(location)>>(36,431) dialog0--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) dialog0--getLeft()=16 getTop()=16 getRight()=1144 getBottom()=1028 dialog0--getX()=16.0      getY()=16.0 dialog0--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--getScrollX()=0  getScrollY()=0 ------------------------------------------- dialog0--0--getGlobalVisibleRect(rect)>>Rect(16, 16 - 1144, 144) dialog0--0--getGlobalVisibleRect(rect, point)>>Rect(16, 16 - 1144, 144)point>>(16,16) dialog0--0--getLocalVisibleRect(rect)>>Rect(0, 0 - 1128, 128) dialog0--0--getLocationInWindow(location)>>(16,16) dialog0--0--getLocationOnScreen(location)>>(36,431) dialog0--0--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) dialog0--0--getLeft()=0 getTop()=0 getRight()=1128 getBottom()=128 dialog0--0--getX()=0.0      getY()=0.0 dialog0--0--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--0--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--0--getScrollX()=0  getScrollY()=0 ------------------------------------------- dialog0--1--getGlobalVisibleRect(rect)>>Rect(16, 144 - 1144, 148) dialog0--1--getGlobalVisibleRect(rect, point)>>Rect(16, 144 - 1144, 148)point>>(16,144) dialog0--1--getLocalVisibleRect(rect)>>Rect(0, 0 - 1128, 4) dialog0--1--getLocationInWindow(location)>>(16,144) dialog0--1--getLocationOnScreen(location)>>(36,559) dialog0--1--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) dialog0--1--getLeft()=0 getTop()=128 getRight()=1128 getBottom()=132 dialog0--1--getX()=0.0      getY()=128.0 dialog0--1--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--1--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--1--getScrollX()=0  getScrollY()=0 ------------------------------------------- dialog0--2--getGlobalVisibleRect(rect)>>Rect(16, 148 - 1144, 1028) dialog0--2--getGlobalVisibleRect(rect, point)>>Rect(16, 148 - 1144, 1028)point>>(16,148) dialog0--2--getLocalVisibleRect(rect)>>Rect(0, 0 - 1128, 880) dialog0--2--getLocationInWindow(location)>>(16,148) dialog0--2--getLocationOnScreen(location)>>(36,563) dialog0--2--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) dialog0--2--getLeft()=0 getTop()=132 getRight()=1128 getBottom()=1012 dialog0--2--getX()=0.0      getY()=132.0 dialog0--2--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--2--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--2--getScrollX()=0  getScrollY()=0 ------------------------------------------- dialog0--2--0--getGlobalVisibleRect(rect)>>Rect(16, 148 - 1144, 1028) dialog0--2--0--getGlobalVisibleRect(rect, point)>>Rect(16, 148 - 1144, 1028)point>>(16,148) dialog0--2--0--getLocalVisibleRect(rect)>>Rect(0, 0 - 1128, 880) dialog0--2--0--getLocationInWindow(location)>>(16,148) dialog0--2--0--getLocationOnScreen(location)>>(36,563) dialog0--2--0--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) dialog0--2--0--getLeft()=0 getTop()=0 getRight()=1128 getBottom()=880 dialog0--2--0--getX()=0.0      getY()=0.0 dialog0--2--0--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--2--0--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--2--0--getScrollX()=0  getScrollY()=0 ------------------------------------------- dialog0--2--0--0--getGlobalVisibleRect(rect)>>Rect(16, 148 - 1144, 1028) dialog0--2--0--0--getGlobalVisibleRect(rect, point)>>Rect(16, 148 - 1144, 1028)point>>(16,148) dialog0--2--0--0--getLocalVisibleRect(rect)>>Rect(0, 0 - 1128, 880) dialog0--2--0--0--getLocationInWindow(location)>>(16,148) dialog0--2--0--0--getLocationOnScreen(location)>>(36,563) dialog0--2--0--0--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) dialog0--2--0--0--getLeft()=0 getTop()=0 getRight()=1128 getBottom()=880 dialog0--2--0--0--getX()=0.0      getY()=0.0 dialog0--2--0--0--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--2--0--0--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--2--0--0--getScrollX()=0  getScrollY()=0 ------------------------------------------- dialog0--2--0--0--0--getGlobalVisibleRect(rect)>>Rect(16, 168 - 116, 368) dialog0--2--0--0--0--getGlobalVisibleRect(rect, point)>>Rect(16, 168 - 116, 368)point>>(-83,168) dialog0--2--0--0--0--getLocalVisibleRect(rect)>>Rect(99, 0 - 199, 200) dialog0--2--0--0--0--getLocationInWindow(location)>>(-83,168) dialog0--2--0--0--0--getLocationOnScreen(location)>>(-63,583) dialog0--2--0--0--0--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) dialog0--2--0--0--0--getLeft()=0 getTop()=20 getRight()=200 getBottom()=220 dialog0--2--0--0--0--getX()=-100.0      getY()=20.0 dialog0--2--0--0--0--getTranslationX()=-100.0  getTranslationY()=0.0 dialog0--2--0--0--0--getTranslationX()=-100.0  getTranslationY()=0.0 dialog0--2--0--0--0--getScrollX()=0  getScrollY()=0 ------------------------------------------- dialog0--2--0--0--1--getGlobalVisibleRect(rect)>>Rect(480, 168 - 680, 368) dialog0--2--0--0--1--getGlobalVisibleRect(rect, point)>>Rect(480, 168 - 680, 368)point>>(480,168) dialog0--2--0--0--1--getLocalVisibleRect(rect)>>Rect(0, 0 - 200, 200) dialog0--2--0--0--1--getLocationInWindow(location)>>(480,168) dialog0--2--0--0--1--getLocationOnScreen(location)>>(500,583) dialog0--2--0--0--1--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) dialog0--2--0--0--1--getLeft()=464 getTop()=20 getRight()=664 getBottom()=220 dialog0--2--0--0--1--getX()=464.0      getY()=20.0 dialog0--2--0--0--1--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--2--0--0--1--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--2--0--0--1--getScrollX()=0  getScrollY()=0 ------------------------------------------- dialog0--2--0--0--2--getGlobalVisibleRect(rect)>>Rect(1044, 168 - 1144, 368) dialog0--2--0--0--2--getGlobalVisibleRect(rect, point)>>Rect(1044, 168 - 1144, 368)point>>(1044,168) dialog0--2--0--0--2--getLocalVisibleRect(rect)>>Rect(0, 0 - 100, 200) dialog0--2--0--0--2--getLocationInWindow(location)>>(1044,168) dialog0--2--0--0--2--getLocationOnScreen(location)>>(1064,583) dialog0--2--0--0--2--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) dialog0--2--0--0--2--getLeft()=928 getTop()=20 getRight()=1128 getBottom()=220 dialog0--2--0--0--2--getX()=1028.0      getY()=20.0 dialog0--2--0--0--2--getTranslationX()=100.0  getTranslationY()=0.0 dialog0--2--0--0--2--getTranslationX()=100.0  getTranslationY()=0.0 dialog0--2--0--0--2--getScrollX()=0  getScrollY()=0 ------------------------------------------- dialog0--2--0--0--3--getGlobalVisibleRect(rect)>>Rect(280, 428 - 880, 1028) dialog0--2--0--0--3--getGlobalVisibleRect(rect, point)>>Rect(280, 428 - 880, 1028)point>>(280,428) dialog0--2--0--0--3--getLocalVisibleRect(rect)>>Rect(0, 0 - 600, 600) dialog0--2--0--0--3--getLocationInWindow(location)>>(280,428) dialog0--2--0--0--3--getLocationOnScreen(location)>>(300,843) dialog0--2--0--0--3--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) dialog0--2--0--0--3--getLeft()=264 getTop()=280 getRight()=864 getBottom()=880 dialog0--2--0--0--3--getX()=264.0      getY()=280.0 dialog0--2--0--0--3--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--2--0--0--3--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--2--0--0--3--getScrollX()=0  getScrollY()=0 ------------------------------------------- dialog0--2--0--0--3--0--getGlobalVisibleRect(rect)>>Rect(280, 428 - 380, 628) dialog0--2--0--0--3--0--getGlobalVisibleRect(rect, point)>>Rect(280, 428 - 380, 628)point>>(181,428) dialog0--2--0--0--3--0--getLocalVisibleRect(rect)>>Rect(99, 0 - 199, 200) dialog0--2--0--0--3--0--getLocationInWindow(location)>>(180,428) dialog0--2--0--0--3--0--getLocationOnScreen(location)>>(200,843) dialog0--2--0--0--3--0--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) dialog0--2--0--0--3--0--getLeft()=0 getTop()=0 getRight()=200 getBottom()=200 dialog0--2--0--0--3--0--getX()=-100.0      getY()=0.0 dialog0--2--0--0--3--0--getTranslationX()=-100.0  getTranslationY()=0.0 dialog0--2--0--0--3--0--getTranslationX()=-100.0  getTranslationY()=0.0 dialog0--2--0--0--3--0--getScrollX()=0  getScrollY()=0 ------------------------------------------- dialog0--2--0--0--3--1--getGlobalVisibleRect(rect)>>Rect(480, 428 - 680, 628) dialog0--2--0--0--3--1--getGlobalVisibleRect(rect, point)>>Rect(480, 428 - 680, 628)point>>(480,428) dialog0--2--0--0--3--1--getLocalVisibleRect(rect)>>Rect(0, 0 - 200, 200) dialog0--2--0--0--3--1--getLocationInWindow(location)>>(480,428) dialog0--2--0--0--3--1--getLocationOnScreen(location)>>(500,843) dialog0--2--0--0--3--1--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) dialog0--2--0--0--3--1--getLeft()=200 getTop()=0 getRight()=400 getBottom()=200 dialog0--2--0--0--3--1--getX()=200.0      getY()=0.0 dialog0--2--0--0--3--1--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--2--0--0--3--1--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--2--0--0--3--1--getScrollX()=0  getScrollY()=0 ------------------------------------------- dialog0--2--0--0--3--2--getGlobalVisibleRect(rect)>>Rect(780, 428 - 880, 628) dialog0--2--0--0--3--2--getGlobalVisibleRect(rect, point)>>Rect(780, 428 - 880, 628)point>>(780,428) dialog0--2--0--0--3--2--getLocalVisibleRect(rect)>>Rect(0, 0 - 100, 200) dialog0--2--0--0--3--2--getLocationInWindow(location)>>(780,428) dialog0--2--0--0--3--2--getLocationOnScreen(location)>>(800,843) dialog0--2--0--0--3--2--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) dialog0--2--0--0--3--2--getLeft()=400 getTop()=0 getRight()=600 getBottom()=200 dialog0--2--0--0--3--2--getX()=500.0      getY()=0.0 dialog0--2--0--0--3--2--getTranslationX()=100.0  getTranslationY()=0.0 dialog0--2--0--0--3--2--getTranslationX()=100.0  getTranslationY()=0.0 dialog0--2--0--0--3--2--getScrollX()=0  getScrollY()=0 ------------------------------------------- dialog0--2--0--0--3--3--getGlobalVisibleRect(rect)>>Rect(480, 628 - 680, 828) dialog0--2--0--0--3--3--getGlobalVisibleRect(rect, point)>>Rect(480, 628 - 680, 828)point>>(480,628) dialog0--2--0--0--3--3--getLocalVisibleRect(rect)>>Rect(0, 0 - 200, 200) dialog0--2--0--0--3--3--getLocationInWindow(location)>>(480,628) dialog0--2--0--0--3--3--getLocationOnScreen(location)>>(500,1043) dialog0--2--0--0--3--3--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) dialog0--2--0--0--3--3--getLeft()=200 getTop()=200 getRight()=400 getBottom()=400 dialog0--2--0--0--3--3--getX()=200.0      getY()=200.0 dialog0--2--0--0--3--3--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--2--0--0--3--3--getTranslationX()=0.0  getTranslationY()=0.0 dialog0--2--0--0--3--3--getScrollX()=0  getScrollY()=0 -------------------------------------------

当我们移动view3时,看出getLeft()系列的值没有改变,但是TranslationX系列的值发生了改变

 view3--getGlobalVisibleRect(rect)>>Rect(57, 1156 - 257, 1356) view3--getGlobalVisibleRect(rect, point)>>Rect(57, 1156 - 257, 1356)point>>(58,1156) view3--getLocalVisibleRect(rect)>>Rect(-1, 0 - 199, 200) view3--getLocationInWindow(location)>>(57,1156) view3--getLocationOnScreen(location)>>(57,1156) view3--getWindowVisibleDisplayFrame(rect)>>Rect(0, 50 - 1200, 1824) view3--getLeft()=1000 getTop()=20 getRight()=1200 getBottom()=220 view3--getX()=57.0      getY()=978.0 view3--getTranslationX()=-943.0  getTranslationY()=958.0 view3--getTranslationX()=-943.0  getTranslationY()=958.0 view3--getScrollX()=0  getScrollY()=0

来些扩展的看看Activity 的视图树(以下视图跟上面的布局没有关系)
AppCompatActivity_NO_ActionBar内容区.png


AppCompatActivity_NO_ActionBar整个界面包含状态栏.png


AppCompatActivity_With_ActionBar内容区


AppCompatActivity_With_ActionBar内容区和ActionBar.png


AppCompatActivity_With_ActionBar整个界面包含状态栏

更多相关文章

  1. Android(安卓)OnGestureListener
  2. Android中GPS/Map的运用
  3. android加载本地图片
  4. 2011.07.20——— android 获得当前view在屏幕的坐标
  5. Android(安卓)根据坐标获取地址
  6. Android学习07-----事件处理(4)键盘事件和触摸事件
  7. Android(安卓)根据坐标获取地址
  8. 2011.07.20——— android 获得当前view在屏幕的坐标
  9. Android学习07-----事件处理(4)键盘事件和触摸事件

随机推荐

  1. Android多媒体学习一:Android中Image的简
  2. Android:实现TabWidget选项卡按钮在屏幕下
  3. Android高手进阶教程(三)之----Android(
  4. Android与后端(javaweb)数据交互,包含文件(流
  5. Rootzwiki 采访 CM 创始人 Steve Kondik
  6. Android(安卓)系统基础
  7. Android用户界面设计:基本按钮
  8. 一个Android登陆/注册XML布局文件代码
  9. Android(安卓)res/raw文件以及raw与res/a
  10. Pro Android(安卓)4 第六章 构建用户界面