如何在启动画面中以编程方式旋转图像而不是使用进度条?
how to rotate an image programmatically in a splashscreen instead of using progressbar?
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);
}
对于 API 11+ 这应该围绕它的中心旋转图像
yourView.setPivotX(yourView.getWidth() / 2);
yourView.setPivotY(yourView.getHeight() / 2);
float rotation = 360f;
yourView.setRotation(rotation);
图片旋转使用以下代码:
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);
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);
}
对于 API 11+ 这应该围绕它的中心旋转图像
yourView.setPivotX(yourView.getWidth() / 2);
yourView.setPivotY(yourView.getHeight() / 2);
float rotation = 360f;
yourView.setRotation(rotation);
图片旋转使用以下代码:
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);