我已经用于动画的2个图像视图,我希望这两个动画之间有延迟。 以下是MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
faded();
faded2();
}
public void faded()
{
ImageView img=(ImageView)findViewById(R.id.imageView2);
img.setBackgroundResource(R.drawable.fade);
AnimationDrawable ani=(AnimationDrawable)img.getBackground();
ani.start();
}
public void faded2()
{
ImageView img=(ImageView)findViewById(R.id.imageView3);
img.setBackgroundResource(R.drawable.fade2);
AnimationDrawable ani=(AnimationDrawable)img.getBackground();
ani.start();
}
}
the above code starts both the animation at same time.
what should i do in order to get a delay between these two?
我应该做些什么改变来获得理想的结果?
答案 0 :(得分:1)
如果您希望淡入ImageViews,可以使用
//Initially set the alpha to 0 so we can't see it
img1.setAlpha(0.0f);
img2.setAlpha(0.0f);
//Then call the animate() on them. Note the startDelay for the second.
img1.animate().alpha(1.0f).setDuration(300).start();
img2.animate().alpha(1.0f).setDuration(300).setStartDelay(200).start();