2017-10-04 3 views
0

저는 애니메이션을위한 2 개의 이미지 뷰를 사용했습니다.이 두 애니메이션 사이에 지연이 필요합니다. MainActivity.javaandroid 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); ** 귀하의 코드에서 – NSimon

관련 문제