如何在启动画面中以编程方式旋转图像而不是使用进度条?

时间:2015-05-05 13:20:14

标签: android rotation functional-programming splash-screen

public class SplashScreen extends Activity {
private static int SPLASH_TIME_OUT = 30000;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            // This method will be executed once the timer is over
            // Start your app main activity
            Intent i = new Intent(SplashScreen.this, MainActivity.class);
            startActivity(i);

            // close this activity
            finish();
        }
    }, SPLASH_TIME_OUT);
}

2 个答案:

答案 0 :(得分:3)

对于图像旋转,请使用以下代码:

ImageView rotate_image =(ImageView) findViewById(R.id.splash_Rotate);
    RotateAnimation rotate = new RotateAnimation(30, 360, Animation.RELATIVE_TO_SELF, 0.5f,  Animation.RELATIVE_TO_SELF, 0.5f);
    rotate.setDuration(2500);
    rotate_image.startAnimation(rotate);

答案 1 :(得分:1)

对于API 11+,这应该围绕它的中心旋转图像

yourView.setPivotX(yourView.getWidth() / 2);
yourView.setPivotY(yourView.getHeight() / 2);

float rotation = 360f;
yourView.setRotation(rotation);