所以我研究瞭如何使用this thread動畫淡化和下拉/滑動視圖的動畫,但它沒有如預期的那樣工作。首先,這裏是我使用的動畫代碼:如何將視圖動畫化並將其下推下方的所有內容?
public void toggleAdvancedVisibility(View text) { //text is a clickable textview thats acts as a toggle
int dur = 1000;
final View advView = findViewById(R.id.enc_advanced);
if(advView.getVisibility() == View.GONE && animationDone) {
advView.setVisibility(View.VISIBLE);
advView.setAlpha(0.0f);
//animate fade + drop down
advView.animate()
.setDuration(dur)
.translationY(advView.getHeight())
.alpha(1.0f)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
animationDone = true;
}
});
animationDone=false;
}
else if(advView.getVisibility() == View.VISIBLE && animationDone) {
//animate fade + slide up
advView.animate()
.setDuration(dur)
.translationY(0)
.alpha(0.0f)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
advView.setVisibility(View.GONE);
animationDone = true;
}
});
animationDone = false;
}
}
正如我所說的,雖然有動畫,這並不像預期的附近的任何地方採取行動。
問題#1 視圖幾乎被推出了可見性。我相信這是由於.translationY(advView.getHeight())
這條線的原因,就好像我將動畫前的視圖位置設置爲advView.setTranslationY(-advView.getHeight())
,然後動畫效果爲.translationY(0)
它會轉到它應該設置的位置。
這個問題的一個明顯問題是,當視圖是動畫時,視圖在它完成之前與視圖「碰撞」。那麼,如何正確地將它滑入/滑出而不會碰到上面的視圖?
問題#2 動畫並不完全「推」下來,這是我的預期。我的意思是,動畫視圖也有一個低於它的視圖。我預計下面的視圖會被動畫視圖壓低。雖然我還沒有嘗試過,但我認爲這可以通過將相同的動畫設置到其下面的視圖來模擬,但還有其他方法嗎?
我對這個動畫的東西很陌生,並且操作這樣的視圖,所以任何幫助表示讚賞。
使用'android.support.design.widget.BaseTransientBottomBar'作爲基類或(如果您需要不同的行爲)查看其源代碼以瞭解它是如何完成的 – pskink
@pskink您是否有特定的鏈接或源我可以使用?我正在閱讀文檔,我相信我在某種程度上理解我應該做什麼,但不確定。我也找不到使用它的任何好例子。 –
問谷歌叔叔'BaseTransientBottomBar.java' – pskink