4

我正在开发一个自定义步进器。一切正常。

我现在要做的是在填充当前步骤时为步进器设置动画。

这张图片显示了我的想法:

这张图片显示了我的想法:

这是我在设置线条、标题和图标 src 的颜色时的代码:

private void DrawStepper(int position) {
    switch (position) {

        case 0:
            imgStepShipper.setImageResource(R.drawable.ic_current_step);
            txtStepShipper.setTextColor(getResources().getColor(R.color.colorPrimary));
            line.setBackgroundColor(getResources().getColor(R.color.colorDarkWhite));

            imgStepConsignee.setImageResource(R.drawable.ic_unselected_step);
            txtStepConsignee.setTextColor(getResources().getColor(R.color.colorDarkSuperWhite));
            line2.setBackgroundColor(getResources().getColor(R.color.colorDarkWhite));

            imgStepShipment.setImageResource(R.drawable.ic_unselected_step);
            txtStepShipment.setTextColor(getResources().getColor(R.color.colorDarkSuperWhite));
            line3.setBackgroundColor(getResources().getColor(R.color.colorDarkWhite));

            imgStepCharges.setImageResource(R.drawable.ic_unselected_step);
            txtStepCharges.setTextColor(getResources().getColor(R.color.colorDarkSuperWhite));

            break;

        case 1:
            imgStepShipper.setImageResource(R.drawable.ic_done_step);
            txtStepShipper.setTextColor(getResources().getColor(R.color.colorPrimary));
            line.setBackgroundColor(getResources().getColor(R.color.colorPrimary));

            imgStepConsignee.setImageResource(R.drawable.ic_current_step);
            txtStepConsignee.setTextColor(getResources().getColor(R.color.colorPrimary));
            line2.setBackgroundColor(getResources().getColor(R.color.colorDarkWhite));

            imgStepShipment.setImageResource(R.drawable.ic_unselected_step);
            txtStepShipment.setTextColor(getResources().getColor(R.color.colorDarkSuperWhite));
            line3.setBackgroundColor(getResources().getColor(R.color.colorDarkWhite));

            imgStepCharges.setImageResource(R.drawable.ic_unselected_step);
            txtStepCharges.setTextColor(getResources().getColor(R.color.colorDarkSuperWhite));

            break;

        case 2:
            imgStepShipper.setImageResource(R.drawable.ic_done_step);
            txtStepShipper.setTextColor(getResources().getColor(R.color.colorPrimary));
            line.setBackgroundColor(getResources().getColor(R.color.colorPrimary));

            imgStepConsignee.setImageResource(R.drawable.ic_done_step);
            txtStepConsignee.setTextColor(getResources().getColor(R.color.colorPrimary));
            line2.setBackgroundColor(getResources().getColor(R.color.colorPrimary));

            imgStepShipment.setImageResource(R.drawable.ic_current_step);
            txtStepShipment.setTextColor(getResources().getColor(R.color.colorPrimary));
            line3.setBackgroundColor(getResources().getColor(R.color.colorDarkWhite));

            imgStepCharges.setImageResource(R.drawable.ic_unselected_step);
            txtStepCharges.setTextColor(getResources().getColor(R.color.colorDarkSuperWhite));

            break;

        case 3:
            imgStepShipper.setImageResource(R.drawable.ic_done_step);
            txtStepShipper.setTextColor(getResources().getColor(R.color.colorPrimary));
            line.setBackgroundColor(getResources().getColor(R.color.colorPrimary));

            imgStepConsignee.setImageResource(R.drawable.ic_done_step);
            txtStepConsignee.setTextColor(getResources().getColor(R.color.colorPrimary));
            line2.setBackgroundColor(getResources().getColor(R.color.colorPrimary));

            imgStepShipment.setImageResource(R.drawable.ic_done_step);
            txtStepShipment.setTextColor(getResources().getColor(R.color.colorPrimary));
            line3.setBackgroundColor(getResources().getColor(R.color.colorPrimary));

            imgStepCharges.setImageResource(R.drawable.ic_current_step);
            txtStepCharges.setTextColor(getResources().getColor(R.color.colorPrimary));
            break;
    }
}

位置是当前步骤。

这是我的用户界面:

这是我的用户界面:

正如我所说,我想在每次从一个步骤移动到另一个步骤时为线条设置动画。

谢谢 :)

4

1 回答 1

1

好吧,你可以让那条线成为progressBar并动画设置它的进度。

这是动画的完成方式: Animate ProgressBar update in Android

或者您可以为视图背景设置动画,只需使用带有动画的可绘制对象,请在此处查看: Android 上视图背景颜色的动画变化

于 2018-04-05T08:14:20.797 回答