开发者

How can I make an ImageView NOT show until after my animation has run?

I have an activity that is a blank screen except for one ImageView object that has it's gravity set to center. Then in my res\anim directory, I animate that image, basically moving it from the bottom of the screen to the center (rising up), using . What I'm trying to figure out is how to have the activity load with a blank screen, not showing the ImageView until after the animation finishes with the image centered. What happens right now is the screen shows with the image already in the center, then the animation takes over and moves it from bottom to top. How Can I make the animation happen first, before showing the ImageView?

EDIT...Please see new/related question below:

OK, the .setVisibilty works (thanks for the help), but it's led me to another problem. In my xml layout file for this activity, I only have 2 objects, a TextView at the top of the screen (using LinearLayout) and then an ImageView that is set to:

    <LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center">

    <ImageView android:id="@+id/Image01"
        android:src="@drawable/image_01"
        android:layout_height="150dp"
        android:layout_width="200dp"
        android:paddingTop="10px"
        >
    </ImageView>

    </LinearLayout>

This puts the image dead c开发者_如何学Pythonenter of the screen. What I want the animation to do is have the image rise from the bottom of the screen to the center. The problem is that even if I have the .setVisibility to INVISIBLE in the onCreate, then set to VISIBLE after I start the animation, it still flashes the image in the dead center of the screen (for about half a second), then immediately drops to the bottom and rises back up to center. This looks sloppy. How can I make the image never show until appears at bottom then rise to the center? I beg for specifics, as I'm just getting feet wet with java and xml.

Final EDIT...

Never mind, this only seems to happen in the emulator. It works fine on the phone.

Thanks for all your help everyone.


Make sure that your image is invisible when the activity starts, by setting the android:visibility attribute to invisible, or by using setVisibility() in onCreate().

Then start the animation and call setVisibility(View.VISIBLE) in one go:

image.startAnimation(...);
image.setVisibility(View.VISIBLE);


I think you want to look at theImageView.setVisibility(View.INVISIBLE).

And you can get information on what your animation is doing (if it's done) with an AnimationListener.

The AnimationListener will have something like this:

AnimationListener a_to_b = new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
                // Do something 
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                // Do something         
            }
        };

and you set it by:

Animation ani = AnimationUtils.loadAnimation(this, R.anim.ani);

ani.setAnimationListener(a_to_b);

Hope this helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜