Java 进度条未设置动画
我试图让进度条在3秒内淡出,但它不起作用Java 进度条未设置动画,java,android,animation,android-animation,mobile-application,Java,Android,Animation,Android Animation,Mobile Application,我试图让进度条在3秒内淡出,但它不起作用 // Animate progress bar. progressBar1 = (ProgressBar) findViewById(R.id.mainImageView1); ObjectAnimator animato = ObjectAnimator.ofFloat(progressBar1, "alpha", 1.0f, 0.0f); animato.setInterpolator(new DecelerateInterp
// Animate progress bar.
progressBar1 = (ProgressBar) findViewById(R.id.mainImageView1);
ObjectAnimator animato = ObjectAnimator.ofFloat(progressBar1, "alpha", 1.0f, 0.0f);
animato.setInterpolator(new DecelerateInterpolator());
animato.setDuration(3000);
animato.start();
布局(xml)
最后,我所说的“工作”是指进度条不会消失。使用AlphaAnimation代替ObjectAnimator>>
AlphaAnimation fade = new AlphaAnimation(1.0f, 0.0f); // from 1 to 0 transparancy
fade.setDuration(1000);
fade.setFillAfter(true) //Keeps ProgressBar at 0 opacity after animation
myProgressBar.startAnimation(fadeOutAnimation);
希望它能起作用:)
顺便说一句,您尚未为进度条分配id,
为进度条分配ID
然后声明一个名为myProgressBar的变量
然后使用progressbar的相应id初始化它。您正试图使用以下行将ImageView强制转换为progressbar:
progressBar1 = (ProgressBar) findViewById(R.id.mainImageView1);
R.id.mainImageView1已在xml中分配给ImageView
在xml中为ProgressBar分配一个id:
<ProgressBar
...
android:id="@+id/progress_bar"
/>
到目前为止,您的代码看起来还不错,请发布您的ProgressBar xml,并详细解释“它不工作”的含义。很抱歉,但它立即崩溃。你好,伙计,Uhh获得帮助了吗??还是我应该多说几句话??抱歉迟到了
<ProgressBar
...
android:id="@+id/progress_bar"
/>
progressBar1 = (ProgressBar) findViewById(R.id.progress_bar);