Android 我想制作一个包含多个图像的启动屏幕
我想做一个随机启动屏幕,这样每次我打开应用程序时都会加载另一个图像Android 我想制作一个包含多个图像的启动屏幕,android,splash-screen,Android,Splash Screen,我想做一个随机启动屏幕,这样每次我打开应用程序时都会加载另一个图像 @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.splash_screen); private int[] splashImages = {R.drawable.splash1, R.drawable.splash2, R.drawable.splash3};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splash_screen);
private int[] splashImages = {R.drawable.splash1, R.drawable.splash2, R.drawable.splash3};
Random random = new Random(System.currentTimeMillis());
int postOfImage = random.nextInt(splashImages.length -1);
有人能告诉我怎么做吗?公共类main活动扩展活动{
public class MainActivity extends Activity {
private static int[] splashImages = { R.drawable.splash1, R.drawable.splash2, R.drawable.splash3 };
ImageView imgSplash;
private SharedPreferences sharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
imgSplash = (ImageView) findViewById(R.id.splash);
int selected;
selected = randomBox();
if (selected == sharedPreferences.getInt("SELECTED", 0)) {
selected = randomBox();
}
Editor editor = sharedPreferences.edit();
editor.putInt("SELECTED", selected);
editor.commit();
for (int i = 0; i < splashImages.length; i++) {
if (selected == i) {
imgSplash.setImageResource(splashImages[i]);
}
}
}
public static int randomBox() {
Random rand = new Random();
int pickedNumber = rand.nextInt(splashImages.length);
return pickedNumber;
}
}
私有静态int[]splashImages={R.drawable.splash1,R.drawable.splash2,R.drawable.splash3};
ImageView imgSplash;
私人共享引用共享引用;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedReferences=PreferenceManager.GetDefaultSharedReferences(此);
imgSplash=(ImageView)findViewById(R.id.splash);
选择int;
所选=随机框();
if(selected==SharedReferences.getInt(“selected”,0)){
所选=随机框();
}
Editor=SharedReferences.edit();
编辑器.putInt(“选定”,选定);
commit();
对于(int i=0;i
Corina,上述代码是否有效?或者有什么问题吗?使用Animation menuAnimation=AnimationUtils.loadAnimation(getActivity(),R.animator.menu\u off\u Animation)代码>。在xml文件.yahh.中定义动画。。使用动画utils或制作一个小视频,并在启动时将视频放在splashscreen上,但在视频中效果不太好。。。因此,请使用动画UtilsIt当我在启动屏幕中使用一幅图像时,我使用了以下代码:new Handler().postDelayed(new Runnable(){@Override public void run(){//创建一个将启动菜单活动的意图//Intent maintent=new Intent(SplashScreen.this,ActivityTypes.class);SplashScreen.this.startActivity(mainIntent);SplashScreen.this.finish();}},SPLASH_显示长度)@CorinaRacasan ya对,你可以实现这个随机函数亲爱的,每次新的图像都会出现show@CorinaRacasan嘿,这对你有用吗?@CorinaRacasan嘿,你忙吗?我只是想知道这个答案。哦,我很抱歉我迟了回答。是的,这对我有用,我的问题现在解决了。非常感谢你@pratik