2017-10-04 77 views
0

我已經使用了2個動畫圖像視圖,並且我希望在這兩個動畫之間有一個延遲。 以下是MainActivity.java如何在android studio中的兩個框架動畫之間添加延遲?

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

如果您正在尋找在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(); 
+0

什麼IMG1和IMG2在這裏? –

+0

您的圖像查看。分別** ** ImageView img1 =(ImageView)findViewById(R.id.imageView2); **和** ImageView img2 =(ImageView)findViewById(R.id.imageView3); ** from your code – NSimon