2016-07-06 179 views
-1

在點擊查看orhu我animatinng ulayout從底部到頂部,並點擊backgroundview我使它從頂部到底部的動畫不可見。但問題是,這兩個動畫只發生在第一次我點擊orbhu。然後沒有動畫發生和視圖只是變得可見和不動畫,除非我重新打開活動。爲什麼是這樣的,我該如何解決這個問題?動畫只發生在第一次

slide_down

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate android:fromYDelta="0%p" android:toYDelta="100%p" android:fillAfter="true" 
     android:interpolator="@android:anim/linear_interpolator" 
     android:duration="500" /> 
</set> 

slide_up

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate android:fromYDelta="100%p" android:toYDelta="0%p" 
     android:fillAfter="true" 
     android:duration="500"/> 
</set> 

代碼

slideDown = AnimationUtils.loadAnimation(mContext, 
     R.anim.slide_down); 
slideUp = AnimationUtils.loadAnimation(mContext, 
     R.anim.slide_up); 
orbhu.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { 
     ulayout.setAnimation(slideUp); 
     ulayout.setVisibility(View.VISIBLE); 
     backgroundview.setVisibility(View.VISIBLE); 
    } 
}); 
backgroundview.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { 
     ulayout.setAnimation(slideDown); 
     backgroundview.setVisibility(View.GONE); 
     ulayout.setVisibility(View.GONE); 
    } 
}); 
+0

嘗試View.Invisible代替View.Gone。 –

+0

@ Hari_krish4同樣的問題wid也是 –

+0

你有沒有嘗試過startAnimation而不是setAnimation –

回答

2

嘗試下面的代碼,而不是

slideDown = AnimationUtils.loadAnimation(mContext, 
     R.anim.slide_down); 
slideUp = AnimationUtils.loadAnimation(mContext, 
     R.anim.slide_up); 
orbhu.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { 
     ulayout.startAnimation(slideUp); 
     ulayout.setVisibility(View.VISIBLE); 
     backgroundview.setVisibility(View.VISIBLE); 
    } 
}); 
backgroundview.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { 
     ulayout.startAnimation(slideDown); 
     backgroundview.setVisibility(View.GONE); 
     ulayout.setVisibility(View.GONE); 
    } 
});