I have a XML layout that contain all my buttons and images and i want a moving cloud on the top of my layout. so i created a view and made my cloud move, however i couldnt link the view with layout. here is my view code
public class CloudView extends View {
Bitmap cloud;
int ChangingX;
public CloudView(Context context) {
// TODO Auto-generated constructor stub
super(context);
cloud = BitmapFactory.decodeResource(getResources(), R.drawable.cloud);
ChangingX = 50;
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
canvas.drawBitmap(cloud, ChangingX , 50, null);
if (ChangingX < canvas.getWidth())
ChangingX += 2;
else
ChangingX = 50;
invalidate();
}
}
and here is my MainActivity
public class MainActivity extends Activity {
CloudView myView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myView = new CloudView(this);
setContentView(myView);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Im new at animation in android can u explain in details how i can link a View with layout. and if it wont work what other classes besides View that i can use.
Thanks for your time and consideration. and sorry for my bad English.