Skip to content

Commit

Permalink
顶上图片跟随进度变化 而不像。下面进度条的那样定死
Browse files Browse the repository at this point in the history
  • Loading branch information
Macsags committed Sep 3, 2020
1 parent 1298c86 commit ed0321d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.macsags.stageview;

import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
Expand Down Expand Up @@ -60,6 +61,8 @@ public void init(int []a) {
stagesBeanList.add(stageBean5);
stagesBeanList.add(stageBean6);
stagesBeanList.add(stageBean7);
int[] drawables = new int[]{R.mipmap.shuipingzuo,R.mipmap.shuangyuzuo,R.mipmap.jinniuzuo,R.mipmap.mojiezuo,R.mipmap.tianchengzuo,R.mipmap.chunvzuo,R.mipmap.juxiezuo,R.mipmap.muyangzuo};
int[] drawables1 = new int[]{R.mipmap.shuipingzuo1,R.mipmap.shuangyuzuo1,R.mipmap.jinniuzuo1,R.mipmap.mojiezuo1,R.mipmap.tianchengzuo1,R.mipmap.chunvzuo1,R.mipmap.juxiezuo1,R.mipmap.muyangzuo1};

stageView.setStageViewTexts(stagesBeanList)
.setTextSize(16)//set textSize
Expand All @@ -70,7 +73,7 @@ public void init(int []a) {
.setStagesViewIndicatorCompleteIcon(ContextCompat.getDrawable(getBaseContext(), R.drawable.yiwancheng))//设置stagesViewIndicator CompleteIcon
.setStagesViewIndicatorDefaultIcon(ContextCompat.getDrawable(getBaseContext(), R.drawable.weiwancheng))//设置stagesViewIndicator DefaultIcon
.setStagesViewIndicatorAttentionIcon(ContextCompat.getDrawable(getBaseContext(), R.drawable.jinxingzhong))
.setStageViewUnComplectedIv(ContextCompat.getDrawable(getBaseContext(), R.mipmap.tianchengzuo1))
.setStageViewComplectedIv(ContextCompat.getDrawable(getBaseContext(), R.mipmap.tianchengzuo));
.setStageViewUnComplectedIv(drawables)
.setStageViewComplectedIv(drawables1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ public class HorizontalStageView extends LinearLayout implements HorizontalStage
private int mComplectingPosition;
private int mUnComplectedTextColor = ContextCompat.getColor(getContext(), R.color.uncompleted_text_color);//定义默认未完成文字的颜色;
private int mComplectedTextColor = ContextCompat.getColor(getContext(), android.R.color.white);//定义默认完成文字的颜色;
private Drawable mUnComplectedIV ;//定义默认未完成iv背景色颜色;
private Drawable mComplectedIV;//定义默认完成iv背景色颜色;
// private Drawable mUnComplectedIV ;//定义默认未完成iv背景色颜色;
// private Drawable mComplectedIV;//定义默认完成iv背景色颜色;
private int mUnComplectedIvs[];
private int mComplectedIvs[];
private int mTextSize = 14;//default textSize
private TextView mTextView;
private ImageView mImageView;
Expand Down Expand Up @@ -66,14 +68,14 @@ private void init() {
public HorizontalStageView setStageViewTexts(List<StageBean> StagesBeanList) {
mStageBeanList = StagesBeanList;
mStagesViewIndicator.setStageNum(mStageBeanList);
int j =-1;
for (int i = 0; i <StagesBeanList.size() ; i++) {
if( StagesBeanList.get(i).getState()==1){
int j = -1;
for (int i = 0; i < StagesBeanList.size(); i++) {
if (StagesBeanList.get(i).getState() == 1) {
j++;
}

}
mComplectingPosition =j;
mComplectingPosition = j;
return this;
}

Expand Down Expand Up @@ -103,23 +105,25 @@ public HorizontalStageView setStageViewComplectedTextColor(int complectedTextCol
/**
* 设置上部未完成图片
*
* @param unComplectedIv
* @param unComplectedIvs
* @return
*/
public HorizontalStageView setStageViewUnComplectedIv(Drawable unComplectedIv) {
mUnComplectedIV = unComplectedIv;
public HorizontalStageView setStageViewUnComplectedIv(int[] unComplectedIvs) {
mUnComplectedIvs = unComplectedIvs;
return this;
}

/**
* 设置完成图片
*
* @param complectedIv
* @param complectedIvs
* @return
*/
public HorizontalStageView setStageViewComplectedIv(Drawable complectedIv) {
this.mComplectedIV = complectedIv;
public HorizontalStageView setStageViewComplectedIv(int[] complectedIvs) {
this.mComplectedIvs = complectedIvs;
return this;
}

/**
* 设置StagesViewIndicator未完成线的颜色
*
Expand Down Expand Up @@ -203,7 +207,7 @@ public void onDrawIndicator() {
int measuredWidth = mTextView.getMeasuredWidth();
mTextView.setX(complectedXPosition.get(i) - measuredWidth / 2);
mTextView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
Log.e("TAG", "onDrawIndicator: "+mComplectingPosition+"------i"+i);
Log.e("TAG", "onDrawIndicator: " + mComplectingPosition + "------i" + i);
if (i <= mComplectingPosition) {
mTextView.setTypeface(null, Typeface.BOLD);
mTextView.setTextColor(mComplectedTextColor);
Expand Down Expand Up @@ -237,18 +241,16 @@ public void onClick(View view) {

if (i <= mComplectingPosition) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mImageView.setBackground(mComplectedIV);
mImageView.setBackgroundResource(mComplectedIvs[i]);
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mImageView.setBackground(mUnComplectedIV);
mImageView.setBackgroundResource(mUnComplectedIvs[i]);
}
}
// mImageView.setBackgroundResource(mStageBeanList.get(i).getStateDrawable());




mImgContainer.addView(mImageView);
}

Expand Down

0 comments on commit ed0321d

Please sign in to comment.