我建立一個自定義視圖包含3個進度條,所以我有一個數組變量,像這樣的:ObjetctAnimator與數組變量
float[] progress = new float[3];
而且我想用「ObjectAnimator」更新具體進展條目;這裏有相關的方法:
public void setProgress(int index, float progress) {
this.progress[index] = (progress<=100) ? progress : 100;
invalidate();
}
public void setProgressWithAnimation(int index, float progress, int duration) {
PropertyValuesHolder indexValue = PropertyValuesHolder.ofInt("progress", index);
PropertyValuesHolder progressValue = PropertyValuesHolder.ofFloat("progress", progress);
ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(this, indexValue, progressValue);
objectAnimator.setDuration(duration);
objectAnimator.setInterpolator(new DecelerateInterpolator());
objectAnimator.start();
}
,但我得到這樣的警告:
我也試圖與二傳手包含數組(setProgress (float[] progress)
),但仍得到了一個錯誤:Method setProgress() with type float not found on target class
所以我會很高興知道如何使用ObjectAnimator數組變量,
感謝
簡單地用'ObjectAnimator#ofInt(對象目標,絃樂propertyName的,詮釋.. 。values)' – pskink
@pskink。謝謝,但我已經嘗試它並得到:'方法setProgress()與類型浮動沒有找到目標類',對不起,我沒有寫在問題,我也試過了... – AsfK