What does top, left, right and bottom mean in Android Rect object

↘锁芯ラ 提交于 2020-04-07 10:49:46

问题


I have an Android project where I should make Apples fall. The apples are painted in a Rect. So I created a function that change the Rect position and repaint. Here's my function :

private void updateApplesPosition() {
    for(Rect rect:fallingDownFruitsList)
        rect.set(rect.left, rect.top +10, rect.right, rect.bottom +10);
}

I have a problem : the Apples don't fall but go from right to left. To make the apples fall I changed the code by this :

private void updateApplesPosition() {
    for(Rect rect:fallingDownFruitsList)
        rect.set(rect.left+10, rect.top, rect.right+10, rect.bottom);
}

回答1:


This image will explain you in detail:

left The X coordinate of the left side of the rectangle

top The Y coordinate of the top of the rectangle

right The X coordinate of the right side of the rectangle

bottom The Y coordinate of the bottom of the rectangle




回答2:


From the docs

Parameters

left The X coordinate of the left side of the rectangle

top The Y coordinate of the top of the rectangle

right The X coordinate of the right side of the rectangle

bottom The Y coordinate of the bottom of the rectangle



来源:https://stackoverflow.com/questions/22589322/what-does-top-left-right-and-bottom-mean-in-android-rect-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!