Android Graphics Library

2021年2月28日


Android Graphics Library

link: https://bytlly.com/1tx31g


























































We need to invoke View setFocusableInTouchMode(true) to enable touch inputs We maintain the bounds ( xMin, xMax, yMin, and yMax ) as int instance variables with package access.. The method moveWithCollisionDetection() moves the ball (according to its speed), and adjusts the position and speed of the ball if collision occurs.. We choose float for these variables as it may involve in mathematically operations.. In the onDraw(), we use Canvas s drawText() to draw the status message We use Paint s setTypeFace(), setTextSize() and setColor() to set the font face, size and color for the text.. It constructs a Box, a Ball, a StatusMessage in its constructor The onKeyUp() process the key inputs and changes the Ball s parameters such as speed and radius.. Android Graphics Library Update The PositionWe then call the update() helper method to update the position of the ball, considering possible collision with the bounding box.. If collision occurs, we adjust the position and speed of the ball accordingly We set the bounding box width and height according to the View s weight and height.. The touch screen can generate events such as touch-down, touch-up and touch-drag.. Android Graphics Library Update The PositionAfter a small delay (via Thread sleep() to suspend the current thread), we invoke View s invalidate() to inform the Android graphics sub-system to re-draw the view.. The method draw() renders this shape via Canvas drawOval() method It has a update() method, which takes the ball as argument, and update the balls position and speed in the buffer.. The drawOval() method takes two arguments - a RectF (rectangle in float) object which specifies the bounds of the circle, and a Paint object carrying the paint properties such as the color and the style.. For the Paint object, we construct an instance with default settings, and set the drawing color via Paint s setColor().. Take note that to enable key inputs, we need to set the View to be focusable, and request for the focus.. For the RectF object, we use RectF s set(float left, float top, float right, float bottom) to specify its bounds with the current balls position. 5ebbf469cd

コメント

最新の日記 一覧

<<  2025年5月  >>
27282930123
45678910
11121314151617
18192021222324
25262728293031

お気に入り日記の更新

テーマ別日記一覧

まだテーマがありません

この日記について

日記内を検索