我一直在嘗試在android中創建動畫視圖,並且我已經完成了該動畫,但問題在於動畫卡在中間的某些時候我不知道爲什麼。爲什麼有時動畫卡在Android上?
我正在做的是我有一個在中間的視圖,該視圖包含水平列表視圖,當一個項目被點擊時,視圖動畫頂部和頂部,當用戶點擊它下降到其原始位置
這裏是動畫代碼。
public class DropDownAnim extends Animation {
private final float targetHeight;
private final View view;
private final boolean down;
public DropDownAnim(View view, float targetHeight, boolean down) {
this.view = view;
this.targetHeight = targetHeight;
this.down = down;
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newHeight;
if (down) {
newHeight = (int) (targetHeight * interpolatedTime);
} else {
newHeight = (int) (targetHeight * (1 - interpolatedTime));
}
view.getLayoutParams().height = newHeight;
view.requestLayout();
}
@Override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
}
@Override
public boolean willChangeBounds() {
return true;
}
}
當包含水平列表視圖和一個項目被點擊我做
DropDownAnim drop = new DropDownAnim(_View, (width_And_Height[1]/100) *
Utils.get_Percentage_For_animate_View_Based_On_Mobile_Resloution(),
true); //true means go to top
drop.setDuration(DURATION);
_View.setAnimation(drop);
_View.startAnimation(drop);
和當視圖頂部
DropDownAnim drop = new DropDownAnim(_View, (width_And_Height[1]/100) * Utils.get_Percentage_For_animate_View_Based_On_Mobile_Resloution(),
false);//false means go to is orignal position
drop.setDuration(DURATION);
_View.setAnimation(drop);
_View.startAnimation(drop);
這是回訪的觀點屏幕的高度。
width_And_Height[1]
當水平滾動視圖是在中心,我就瘋狂點擊上升,當水平滾動視圖是在上面,我點擊地圖談到了一部開拓創新位置第一。
但現在的問題是,有時認爲不來了,從頂部的一部開拓創新的位置,卡在中間
這裏的圖像。
當水平滾動視圖是在屏幕
的中間時,水平滾動視圖是在頂部屏幕的
當這種觀點並沒有從最高層和最高層來到原來的位置科軍在中間
我不知道是什麼問題
感謝的製作時間,我的問題,並請幫助:)
當你投下一個問題或答案,請給出理由...... – 2015-02-09 15:42:38
請刪除視圖。requestLayout()from applyTransformation並在動畫開始後只寫一次 – 2015-02-14 05:24:15