0

我知道这个问题已经被问过好几次了,但我就是不知道在哪里放置代码并不断出错。它是图像上的基本淡入动画,我首先希望它是不可见的,然后淡入。在此先感谢我的动画 xml,然后是类的 java。

XML:

<?xml version="1.0" encoding="UTF-8"?>
   <set xmlns:android="http://schemas.android.com/apk/res/android">
     <alpha android:fromAlpha="0.0" android:toAlpha="1.0" 
      android:interpolator="@android:anim/accelerate_interpolator" 
      android:duration="4000"/>
 </set>

爪哇:

package com.example.whattodo2;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class Title extends Activity {
Button reset, rts;
ImageView title;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_title);
    reset = (Button) findViewById(R.id.reset);
    reset.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                       double rand = Math.random();
                       if(rand < 0.5){
                           Intent reset1 = new Intent(Title.this, MainActivity.class);
                           startActivity(reset1);
                       } else {
                           Intent reset2 = new Intent(Title.this, Question36.class);
                           startActivity(reset2);
                       }
                }
            });
    rts = (Button) findViewById(R.id.rts);
    rts.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    Intent rts=new Intent(Title.this,Rts.class);
                    startActivity(rts);

                }
            });

         final Animation a = AnimationUtils.loadAnimation(this, R.animator.animation);
         a.reset();
         final ImageView rImage = (ImageView) findViewById(R.id.title);

         RelativeLayout layout = (RelativeLayout) findViewById(R.id.root);
         layout.setOnClickListener(new OnClickListener() {

             @Override public void onClick(View v) {
         rImage.startAnimation(a);
         func(); //A call to the function.

         }
         });


}

protected void func() {
    // TODO Auto-generated method stub

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.title, menu);
    return true;
}

}
4

3 回答 3

1

您可以使用droidQuery来完成动画:

$.with(rImage).attr("alpha", 0f).animate("{ alpha    : 1.0 }",
                    new AnimationOptions("{ duration : 4000,
                                            easing   : accelerate }"));
于 2013-08-05T13:32:57.263 回答
1

删除 rImage.startAnimation(); 来自点击监听器。

Animation a = AnimationUtils.loadAnimation(this, R.animator.animation);
ImageView rImage = (ImageView) findViewById(R.id.title);
rImage.startAnimation(a);
于 2013-08-05T12:27:11.070 回答
0

看你不能在onCreate中启动动画,因为它不是粘在主ui上的东西,搜索更多

这是一个可以帮助您的链接。

动画

于 2013-08-05T12:30:57.010 回答