I want to move the image on screen using thread I have tried but its not working fine due to improper code of thread. I am able to get the image and i want to move the image on screen In this code i want to move ovalshaped image and i dont want that it must effect the jerry image but the problem is thread is also implementing over it The margenMaxX, margenxy are the maximum width and height
public class AnimatedView extends ImageView {
public AnimatedView(Context context) {
super(context);
Resources res = context.getResources();
drawable = res.getDrawable(R.drawable.jerry);
mDrawable = new ShapeDrawable(new OvalShape());
mDrawable.getPaint().setColor(0xffffAC23);
}
protected void onDraw(final Canvas cc) {
final Context context = null;
drawable.setBounds(x , y , x + width, y + height);
drawable.draw(cc);
invalidate();
Thread thread = new Thread()
{
@Override
public void run() {
try {
while(i<=margenMaxX && j<=margenmaxy) {
sleep(100);
// context.runOnUiThread(new Runnable() {
//handler.post(r);
runOnUiThread(new Runnable() {
@Override
public void run() {
mDrawable.setBounds(i, j ,i+ width, i+ height);
mDrawable.draw(cc);
}
});
//invalidate();
i=i+10;
j=j+10;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
thread.start();
}