對(duì)象容器

import android.view.*;

import android.graphics.*;

public class 對(duì)象容器 extends 對(duì)象{

private int downx=0,downy=0;

private int[] dxX,dxY;

public boolean w=true,h=true;

public Bitmap 背景=null;

public int 背景顏色=Color.argb(255,100,100,100);

public int 對(duì)象間距=10;

public Paint 邊框=null;

public 對(duì)象容器(int x,int y,int width,int height){

super(x,y,width,height);

類名="對(duì)象容器";

}

public void 顯示(Canvas c){

if(顯示)行為(c);

};

public void 事件(MotionEvent e){

if(事件){

行為(e);

運(yùn)行內(nèi)部對(duì)象(e);

if(e.getAction()==MotionEvent.ACTION_UP){

移動(dòng)=false;

按下=false;

}

}

}

public void 行為(MotionEvent e){

if(e.getAction()==MotionEvent.ACTION_DOWN){

按下=計(jì)算.如果在某個(gè)矩形范圍(this,e);

if(按下){

記錄內(nèi)部對(duì)象位置();

downx=(int)e.getX();

downy=(int)e.getY();

}

}

if(e.getAction()==MotionEvent.ACTION_MOVE){

if(按下){

if(計(jì)算.絕對(duì)值((int)e.getX(),downx)>10||計(jì)算.絕對(duì)值((int)e.getY(),downy)>10)

移動(dòng)=true;

if(內(nèi)部對(duì)象!=null){

int x=(int)e.getX()-downx;

int y=(int)e.getY()-downy;

移動(dòng)內(nèi)部對(duì)象(x,y);

}

}

}

if(e.getAction()==MotionEvent.ACTION_UP){

if(按下){

dxX=null;

dxY=null;

}

}

}

public void 行為(Canvas c){

drawbeijing(c,背景顏色);

}

public void drawbeijing(Canvas c,int color){

Bitmap bj=Bitmap.createBitmap(寬,高,Bitmap.Config.ARGB_8888);

Canvas cc=new Canvas(bj);

if(背景!=null)cc.drawBitmap(背景,0,0,null);

cc.drawColor(color);

if(內(nèi)部對(duì)象!=null&&內(nèi)部對(duì)象顯示)運(yùn)行內(nèi)部對(duì)象(cc);

if(邊框!=null)圖形.畫矩形(0,0,寬-1,高-1,cc,邊框);

c.drawBitmap(bj,x,y,null);

}

public void 移動(dòng)內(nèi)部對(duì)象(int x,int y){

int i=0;

if(內(nèi)部對(duì)象!=null&&dxX!=null&&dxY!=null)

while(i<內(nèi)部對(duì)象.length){

if(w)內(nèi)部對(duì)象[i].x=dxX[i]+x;

if(h)內(nèi)部對(duì)象[i].y=dxY[i]+y;

i++;

}

}

public void 記錄內(nèi)部對(duì)象位置(){

int i=0;

if(內(nèi)部對(duì)象!=null)

while(i<內(nèi)部對(duì)象.length){

dxX=合并.合并(dxX,內(nèi)部對(duì)象[i].x);

dxY=合并.合并(dxY,內(nèi)部對(duì)象[i].y);

i++;

}

}

public void 運(yùn)行內(nèi)部對(duì)象(MotionEvent e){

e.setLocation(e.getX()-x,e.getY()-y);

if(按下)super.運(yùn)行內(nèi)部對(duì)象(e);

e.setLocation(e.getX()+x,e.getY()+y);

}

public void X方向裝入對(duì)象(對(duì)象 dx){

if(內(nèi)部對(duì)象==null){

dx.x=0;

裝入對(duì)象(dx);

}else{

dx.x=內(nèi)部對(duì)象[內(nèi)部對(duì)象.length-1].x+內(nèi)部對(duì)象[內(nèi)部對(duì)象.length-1].寬+對(duì)象間距;

裝入對(duì)象(dx);

}

}

public void Y方向裝入對(duì)象(對(duì)象 dx){

if(內(nèi)部對(duì)象==null){

dx.y=0;

裝入對(duì)象(dx);

}else{

dx.y=內(nèi)部對(duì)象[內(nèi)部對(duì)象.length-1].y+內(nèi)部對(duì)象[內(nèi)部對(duì)象.length-1].高+對(duì)象間距;

裝入對(duì)象(dx);

}

}

public void 設(shè)置邊框(int 寬度,int 顏色){

邊框=new Paint();

邊框.setStyle(Paint.Style.STROKE);

邊框.setTextSize(寬度);

邊框.setColor(顏色);

}

}


顧名思義這個(gè)類是一個(gè)對(duì)象的容器,一個(gè)對(duì)象通過裝入對(duì)象這個(gè)方法裝入這個(gè)容器,可以通過觸控移動(dòng)容器里的所有對(duì)象,容器里的對(duì)象坐標(biāo)保持相對(duì)不變。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1. Java基礎(chǔ)部分 基礎(chǔ)部分的順序:基本語法,類相關(guān)的語法,內(nèi)部類的語法,繼承相關(guān)的語法,異常的語法,線程的語...
    子非魚_t_閱讀 34,638評(píng)論 18 399
  • import android.view.*; import android.graphics.*; public ...
    一個(gè)愛上浪漫的人閱讀 233評(píng)論 0 0
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,534評(píng)論 19 139
  • ViewDragHelper實(shí)例的創(chuàng)建 ViewDragHelper重載了兩個(gè)create()靜態(tài)方法public...
    傀儡世界閱讀 732評(píng)論 0 3
  • 美好的,留在心底; 遺憾的,隨風(fēng)散去。 活在當(dāng)下,且行且珍惜。
    袁益君閱讀 269評(píng)論 1 2

友情鏈接更多精彩內(nèi)容