Android仿摩拜单车共享单车进度条实现StepView效果

  

先看效果图:

  

 Android仿摩拜单车共享单车进度条实现StepView效果

  

<强>步骤1:定义StepBean

  

定义五个状态,分别为:为完成,正在进行,已完成,终点完成,终点未完成。

        公开课StepBean {   公共静态最终int STEP_UNDO=1;//未完成   公共静态最终int STEP_CURRENT=0;//正在进行   公共静态最终int STEP_COMPLETED=1;//已完成   公共静态最终int STEP_LAST_COMPLETED=2;//终点完成   公共静态最终int STEP_LAST_UNCOMPLETED=3;//终点未完成   私人字符串名称;   私人int状态;   公共字符串getName () {   返回名称;   }   公共空间setName(字符串名称){   this.name=名称;   }   公共int getState () {   返回状态;   }   公共空间设置状态(int状态){   这一点。=状态;   }   公共StepBean () {   }   公共StepBean(字符串名称,int状态){   this.name=名称;   这一点。=状态;   }   }      

<强>步骤2:自定义HorizontalStepsViewIndicator

        公开课HorizontalStepsViewIndicator扩展视图{   私人int defaultStepIndicatorNum=(int) TypedValue.applyDimension (TypedValue。.getDisplayMetrics COMPLEX_UNIT_DIP 40 getresource()());//定义默认的高度   私人浮动mCompletedLineHeight;//完成线的高度   私人浮动mCircleRadius;//圆的半径   私人可拉的mCompleteIcon;//完成的默认图片   私人可拉的mAttentionIcon;//正在进行的默认图片   私人可拉的mDefaultIcon;//默认的背景图   私人可拉的mLastCompleteIcon;//终点未完成图片   私人可拉的mLastUnCompleteIcon;//终点完成图片   私人浮动mCenterY;//该视图的Y轴中间位置   私人浮动mLeftY;//左上方的Y位置   私人浮动mRightY;//右下方的位置   私人ListmStepBeanList;//当前有几步流程   私人int mStepNum=0;   私人浮动mLinePadding;//两条连线之间的间距   私人ListmCircleCenterPointPositionList;//定义所有圆的圆心点位置的集合   私人油漆mUnCompletedPaint;//未完成涂料   私人油漆mCompletedPaint;//完成涂料   私人int mUnCompletedLineColor=ContextCompat.getColor (getContext (), R.color.uncompleted_color);//定义默认未完成线的颜色   私人int mCompletedLineColor=ContextCompat.getColor (getContext (), R.color.completed_color);//定义默认完成线的颜色   私人PathEffect mEffects;   私人int mComplectingPosition;//正在进行位置   私人mPath路径;   私人>   公共类LinearLayout HorizontalStepView扩展实现HorizontalStepsViewIndicator.OnDrawIndicatorListener {   私人RelativeLayout mTextContainer;   私人HorizontalStepsViewIndicator mStepsViewIndicator;   私人ListmStepBeanList;   私人int mComplectingPosition;   私人int mUnComplectedTextColor=ContextCompat.getColor (getContext (), R.color.uncompleted_text_color);//定义默认未完成文字的颜色;   私人int mComplectedTextColor=ContextCompat.getColor (getContext (), R.color.completed_color);//定义默认完成文字的颜色;   私人int mTextSize=14;//默认textSize   私人TextView mTextView;   公共HorizontalStepView(上下文语境){   这(上下文,null);   }   公共HorizontalStepView(上下文语境,AttributeSet attrs) {   这(上下文、attrs 0);   }   公共HorizontalStepView(上下文语境、AttributeSet attrs int defStyleAttr) {   超级(上下文、attrs defStyleAttr);   init ();   }   私人空间init () {   视图rootView=LayoutInflater.from (getContext ()) .inflate (R.layout.widget_horizontal_stepsview,);   mStepsViewIndicator=(HorizontalStepsViewIndicator) rootView.findViewById (R.id.steps_indicator);   mStepsViewIndicator.setOnDrawListener(这个);   mTextContainer=(使用)rootView.findViewById (R.id.rl_text_container);   }/* *   *设置显示的文字   * @param stepsBeanList   * @return   */公共HorizontalStepView setStepViewTexts (ListstepsBeanList) {   mStepBeanList=stepsBeanList;   mStepsViewIndicator.setStepNum (mStepBeanList);   返回;   }/* *   *设置未完成文字的颜色   * @param unComplectedTextColor   * @return   */公共HorizontalStepView setStepViewUnComplectedTextColor (int unComplectedTextColor) {   mUnComplectedTextColor=unComplectedTextColor;   返回;   }/* *   *设置完成文字的颜色   * @param complectedTextColor   * @return   */公共HorizontalStepView setStepViewComplectedTextColor (int complectedTextColor) {   这一点。mComplectedTextColor=complectedTextColor;   返回;   }/* *   *设置StepsViewIndicator未完成线的颜色   * @param unCompletedLineColor   * @return   */公共HorizontalStepView setStepsViewIndicatorUnCompletedLineColor (int unCompletedLineColor) {   mStepsViewIndicator.setUnCompletedLineColor (unCompletedLineColor);   返回;   }/* *   *设置StepsViewIndicator完成线的颜色   * @param completedLineColor   * @return   */公共HorizontalStepView setStepsViewIndicatorCompletedLineColor (int completedLineColor) {   mStepsViewIndicator.setCompletedLineColor (completedLineColor);   返回;   }/* *   *设置StepsViewIndicator默认图片   * @param defaultIcon   */公共HorizontalStepView setStepsViewIndicatorDefaultIcon(可拉的defaultIcon) {   mStepsViewIndicator.setDefaultIcon (defaultIcon);   返回;   }/* *   *设置StepsViewIndicator已完成图片   * @param completeIcon   */公共HorizontalStepView setStepsViewIndicatorCompleteIcon(可拉的completeIcon) {   mStepsViewIndicator.setCompleteIcon (completeIcon);   返回;   }/* *   *设置StepsViewIndicator正在进行中的图片   * @param attentionIcon   */公共HorizontalStepView setStepsViewIndicatorAttentionIcon(可拉的attentionIcon) {   mStepsViewIndicator.setAttentionIcon (attentionIcon);   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

Android仿摩拜单车共享单车进度条实现StepView效果