As I doubted and Described Here You cannot use view animations inside the canvas objects since they belongs to Graphics Class.
Here is A simple code which may help you get started.
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView( new MyView(MainActivity.this));
}
class MyView extends View
{
Rect rect;
Paint paint;
public MyView(Context context) {
// TODO Auto-generated constructor stub
super(context);
init();
}
public void init()
{
paint= new Paint();
paint.setStyle(Style.FILL);
paint.setColor(Color.BLUE);
rect= new Rect(100, 100, 100, 100);
}
@Override
protected void onDraw(final Canvas canvas) {
// TODO Auto-generated method stub
canvas.drawRect(rect, paint);
new Thread( new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
for(int i=100;i<1000;i++)
{
rect.union(100, 100, i, i);
postInvalidate();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
}
}
}