One of the strengths of the iPhone user interface is that things gel together very well. If you click into something, it'll slide or move about to give you an idea of what the app is doing.
Android can do it too, so don't let your app be thought of as an inferior product because of something like that.
To animate between views, you'll need to be using a layout on your Activity. This layout will remain on your activity as the base on which every other view will sit upon.
01.
public
class
YourActivity
extends
Activity {
02.
@Override
public
void
onCreate(Bundle savedInstanceState) {
03.
super
.onCreate(savedInstanceState);
04.
05.
Animation animation;
06.
View viewLoading =
new
NowLoadingView();
07.
08.
// Set up the view animator
09.
m_viewAnimator =
new
ViewAnimator(
this
);
10.
m_viewAnimator.setAnimateFirstView(
true
);
11.
12.
animation =
new
AlphaAnimation(
0
.0f,
1
.0f);
13.
animation.setDuration(
2000
);
14.
m_viewAnimator.setInAnimation(animation);
15.
16.
animation =
new
AlphaAnimation(
1
.0f,
0
.0f);
17.
animation.setDuration(
2000
);
18.
m_viewAnimator.setOutAnimation(animation);
19.
20.
this
.setContentView(m_viewAnimator);
21.
22.
m_viewAnimator.removeAllViews();
23.
m_viewAnimator.addView(viewLoading);
This will now fade in your "loading" view. When its time to change the view, simply remove everything and then add the next one. This will automatically fade out the old and fade in the new.
1.
m_viewAnimator.removeAllViews();
2.
m_viewAnimator.addView(
new
TitleScreenView());
You can use any transition you wish, just take a look through the docs for animations which suit your use case.
- AlphaAnimation will fade your views
- AnimationSet allows multiple animations to be applied at once
- RotateAnimation will rotate
- ScaleAnimation will resize
- and TranslateAnimation will move the view about
An example of using the TranslateAnimation to slide in from the right is below:
1.
Animation animation;
2.
3.
animation =
new
TranslateAnimation(
4.
Animation.RELATIVE_TO_SELF,
1
.0f, Animation.RELATIVE_TO_SELF,
0
.0f,
5.
Animation.RELATIVE_TO_SELF,
0
.0f, Animation.RELATIVE_TO_SELF,
0
.0f
6.
);
7.
8.
animation.setDuration(
400
);
Have fun!