안녕하세요?
Frame Animation을 써서 이미지를 touch하면 회전하고 다시 touch 하면 정지하는것까지 구현 했습니다.
그런데 시간이 지나면 천천히 정지하는것을 구현하려니까 Frame Animation가지고 어떻게 해야 되는지 모르겠습니다.
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/testwheel000" android:duration="10" />
<item android:drawable="@drawable/testwheel015" android:duration="10" />
</animation-list>
XML은 이렇게 밖에 지정하는게 없고 JAVA에서 AnimationDrawable frameAnimation 로 정의해서
frameAnimation.stop(); 을 불러와야 되는데요...
천천히 자연스럽게 정지하도록 만드는걸 못하겠네요.
Touch 를 하면 이미지가 돌고 일정 시간이 지나면 자연스럽게 정지하도록 하려면 어떻게 해야 할까요?
저는 Thread를 돌려서 하려고 했는데 안되네요. 제가 시도했던 소스는 아래와 같습니다.
public class GraphicSurface2 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(new CustomView(this));
}
class CustomView extends SurfaceView implements SurfaceHolder.Callback {
private CustomViewThread CVThread;
private int x = 70;
private int y = 70;
public CustomView(Context context) {
super(context);
getHolder().addCallback(this);
CVThread = new CustomViewThread(getHolder(), this);
setFocusable(true);
}
@Override
public void onDraw(Canvas canvas) {
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.testwheel000);
canvas.drawColor(Color.parseColor("#dedede"));
canvas.drawBitmap(bm, x- (bm.getWidth() / 2), y - (bm.getHeight() / 2), null);
}
public void onDraw2(Canvas canvas, int degree) {
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.testwheel000);
canvas.drawColor(Color.parseColor("#dedede"));
int w = bm.getWidth();
int h = bm.getHeight();
// Setting post rotate to
Matrix mtx = new Matrix();
mtx.postRotate(degree);
// Rotating Bitmap
Bitmap rotatedBMP = Bitmap.createBitmap(bm, 0, 0, w, h, mtx, true);
canvas.drawBitmap(rotatedBMP, x- (rotatedBMP.getWidth() / 2), y - (rotatedBMP.getHeight() / 2), null);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() != MotionEvent.ACTION_DOWN)
{
x = (int) event.getX();
y = (int) event.getY();
}
return true;
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
CVThread.setRunning(true);
CVThread.start();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
CVThread.setRunning(false);
while (retry) {
try {
CVThread.join();
retry = false;
} catch (InterruptedException e) {
}
}
}
}
class CustomViewThread extends Thread {
private SurfaceHolder surfaceholder;
private CustomView customview;
private boolean running = false;
public CustomViewThread(SurfaceHolder surfaceHolder, CustomView CustomView) {
surfaceholder = surfaceHolder;
customview = CustomView;
}
public void setRunning(boolean run) {
running = run;
}
@Override
public void run() {
Canvas c;
int j;
while (running) {
c = null;
try {
c = surfaceholder.lockCanvas(null);
synchronized (surfaceholder) {
for(int i =0; i < 6; i++) {
j = (i+1) * 15;
customview.onDraw2(c,j);
Thread.sleep(500);
}
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (c != null) {
surfaceholder.unlockCanvasAndPost(c);
}
}
}
}
}
}
에니메이션에 적용하는 인터폴레이터 라는 넘이 있습니다.
그걸 자세히 찾아보세요.