首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

圆球运动效果

2012-11-01 
球体运动效果看个效果图:自定义的View:package eas.orgimport android.content.Contextimport android.g

球体运动效果
看个效果图:





自定义的View:

package eas.org;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;public class ColorBall {private Bitmap img; // the image of the ballprivate int coordX = 0; // the x coordinate at the canvasprivate int coordY = 0; // the y coordinate at the canvasprivate int id;// gives every ball his own id, for now not necessaryprivate static int count = 1;private boolean goRight = true;private boolean goDown = true;public ColorBall(Context context, int drawable) {BitmapFactory.Options opts = new BitmapFactory.Options();opts.inJustDecodeBounds = true;// 得到解析的位图img = BitmapFactory.decodeResource(context.getResources(), drawable);id = count;count++;}public static int getCount() {return count;}void setX(int newValue) {coordX = newValue;}public int getX() {return coordX;}void setY(int newValue) {coordY = newValue;}public int getY() {return coordY;}public int getID() {return id;}public Bitmap getBitmap() {return img;}public void moveBall(int goX, int goY) {// check the borders, and set the direction if a border has reachedif (coordX > 270) {goRight = false;}if (coordX < 0) {goRight = true;}if (coordY > 400) {goDown = false;}if (coordY < 0) {goDown = true;}// move the x and yif (goRight) {coordX += goX;} else {coordX -= goX;}if (goDown) {coordY += goY;} else {coordY -= goY;}}}

热点排行