위에서 아래로 이미지가 떨어지는 것을구현하려합니다.
자바로는 아래와같이 구현이 되는데
이걸 안드로이드로 구현을 어떻게해야할지모르겠습니다.
혹시 가능하다면 어떤방법으로 해야하는지 알려주세요~
public class Main extends JFrame implements Runnable{
Random r=new Random();
ArrayList<paintrect> list = new ArrayList<paintrect>();
class paintrect extends JPanel{
int x=0;
int y=0;
public paintrect(int x){
this.x=x;
}
public void paint(Graphics g){
g.drawRect(0, 0, 9, 9);
}
}
public Main(){
setBounds(200,200,300,300);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(null);
}
public void run() {
int cnt=30;
while(true){
if(cnt==30){
cnt=0;
list.add(new paintrect(r.nextInt(280)));
list.get(list.size()-1).setSize(10, 10);
add(list.get(list.size()-1));
}
for(int i=0; i<list.size(); i++){
list.get(i).y += 1;
list.get(i).setLocation(list.get(i).x, list.get(i).y);
}
try {
Thread.sleep(30);
cnt++;
} catch (InterruptedException e) {}
}
}
public static void main(String[] args) {
Main a = new Main();
Thread thd = new Thread(a);
thd.start();
}
}
커스텀 패널을 만들어 paint를 오버라이딩 하듯이..
안드로이드도 커스텀뷰를 만들어 draw를 오버라이딩하고
만들어진뷰를 엑티비티에 붙이시면 됩니다.