3

我在 ProgressIndicatorView 类中有以下内容。该视图在使用时包含以下五个矩形:

当用户按下“Fortsæt”按钮时,我调用视图方法 setProgressIndicator(int step) 将视图中下一个矩形的颜色设置为完全不透明。该方法如下所示:

public void setProgressIndicator(int activeStep) {
        // Fade IN
        TransitionDrawable transition = (TransitionDrawable) this.getChildAt(activeStep-1).getBackground();
        transition.startTransition(transitionTime);
}

init 方法看起来像这样

private void init(Context context) {
    this.setOrientation(LinearLayout.HORIZONTAL);

    transitionColor = getResources().getDrawable(R.drawable.colortransition);
    for (int i = 0; i < squareAmount; i++) {
        ImageView loadingPiece = new ImageView(context);
        //loadingPiece.setBackgroundColor(transparentWhite);
        loadingPiece.setBackgroundDrawable(transitionColor);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0,
                LinearLayout.LayoutParams.FILL_PARENT, 1.0f);
        lp.setMargins(0, 15, 4, 15);
        this.addView(loadingPiece, lp);           
    }
}

如果我使用静态背景颜色作为资源,则该方法非常有效,但当我使用可绘制的 transitioncolor 时则无效。关于可能导致问题的任何建议?

编辑:为澄清起见,这是我使用 this.getChildAt(activeStep-1).setBackgroundColor(opaqueWhite); 时的视图。

在此处输入图像描述

但这就是我使用 setProgressIndicator 的当前实现时的样子:

在此处输入图像描述

是什么导致这种情况发生?

编辑:如果无法找到此问题的原因,是否有另一种方法可以实现此效果?

4

0 回答 0