位置: 编程技术 - 正文

android 水平progressBar动态加载(Android 水平居中)

编辑:rootadmin

推荐整理分享android 水平progressBar动态加载(Android 水平居中),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:Android 水平居中,Android 水平布局,Android 水平滚动不显示子视图,Android 水平换行,Android 水平换行,Android 水平居中,Android 水平居中,Android 水平布局,内容如对您有帮助,希望把文章链接给更多的朋友!

当你需要动态显示一个progressBar时,动态显示进度,并在右侧显示加载进度,请参考下面代码:

重写写布局

public class LineProgressBar extends View {private Paint paint;private int lineColor;private int lineProgressColor;private int textColor;private float textSize;private float textWidth;private float textMargin;private float lineHeight;private int max;private int progress = 0;private RectF pLine, bLine;private int progressOne;public LineProgressBar(Context context) {this(context, null);}public LineProgressBar(Context context, AttributeSet attrs) {this(context, attrs, 0);}public LineProgressBar(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);progressOne = 0;paint = new Paint();TypedArray mTypedArray = context.obtainStyledAttributes(attrs,R.styleable.LineProgressBar);// 获取自定义属性和默认&#;lineColor = mTypedArray.getColor(R.styleable.RoundProgressBar_lineColor, Color.RED);lineHeight = mTypedArray.getDimension(R.styleable.RoundProgressBar_lineHeight, );lineProgressColor = mTypedArray.getColor(R.styleable.RoundProgressBar_lineProgressColor, Color.GREEN);textColor = mTypedArray.getColor(R.styleable.RoundProgressBar_textColor, Color.GREEN);textSize = mTypedArray.getDimension(R.styleable.RoundProgressBar_textSize, );textWidth = mTypedArray.getDimension(R.styleable.RoundProgressBar_textWidth, );textMargin = mTypedArray.getDimension(R.styleable.RoundProgressBar_textMargin, 5);max = mTypedArray.getInteger(R.styleable.RoundProgressBar_max, );mTypedArray.recycle();pLine = new RectF();}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);float width = getWidth();float height = getHeight();float margin = (height - lineHeight)/2;float drawHeight = lineHeight &#; margin;if(bLine == null) bLine = new RectF(0, margin, width-textWidth-textMargin, drawHeight);paint.setColor(lineColor); // 设置背景颜色paint.setStyle(Paint.Style.FILL); // 设置填充paint.setAntiAlias(true); // 消除锯齿canvas.drawRoundRect(bLine, 5, 5, paint); //画进度背景paint.setStrokeWidth(0);paint.setColor(textColor);//设置字体颜色paint.setTextSize(textSize);//设置字体大小paint.setTypeface(Typeface.DEFAULT); // 设置字体int percent = (int) (((float) progressOne / (float) max) * ); canvas.drawText(percent &#; "%", width - textWidth - textMargin, height, paint); // 画出进度百分比paint.setColor(lineProgressColor);//设置进度颜色pLine.set(0, margin, progressOne*(width-textWidth-textMargin)/max, drawHeight);canvas.drawRoundRect(pLine, 5, 5, paint);//画进度if (progressOne < progress) {//循环画invalidate();progressOne&#;&#;;}}public synchronized int getMax() {return max;}public synchronized void setMax(int max) {if (max < 0) {throw new IllegalArgumentException("max not less than 0");}this.max = max;}public synchronized int getProgress() {return progress;}public synchronized void setProgress(int progress) {if (progress < 0) {throw new IllegalArgumentException("progress not less than 0");}if (progress > max) {progress = max;}if (progress <= max) {this.progress = progress;progressOne = 0;postInvalidate();}}public int getTextColor() {return textColor;}public void setTextColor(int textColor) {this.textColor = textColor;}public float getTextSize() {return textSize;}public void setTextSize(float textSize) {this.textSize = textSize;}}

用到的其他代码:

<declare-styleable name="LineProgressBar"> <attr name="textColor" format="color" /> <attr name="textSize" format="dimension" /> <attr name="max" format="integer"></attr> <attr name="textIsDisplayable" format="boolean"></attr> <attr name="lineColor" format="color" /> <attr name="lineHeight" format="dimension" /> <attr name="lineProgressColor" format="color" /> <attr name="textWidth" format="dimension" /> <attr name="textMargin" format="dimension" /> </declare-styleable>

android 水平progressBar动态加载(Android 水平居中)

使用方式:xml

<....LineProgressBar android:id="@&#;id/details_line_progress" android:layout_width="match_parent" android:layout_height="dp" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android_custom:lineColor="@color/whitebl" android_custom:lineHeight="5dp" android_custom:lineProgressColor="@color/title_color" android_custom:max="" android_custom:textColor="@color/title_color" android_custom:textMargin="5dp" android_custom:textSize="sp" android_custom:textWidth="dp" ></....LineProgressBar>

使用方式:代码

LineProgressBar progress;

....//初始化

progress.setProgress();

关于获取本机ip的问题 最经在做项目的时候发现一个问题,我使用手机获取手机在一个局域网内的ip的时候出现了获取ip出错的问题,我使用的方法是://获取本机IPpublicstaticStr

Android学习 - 自定义输入法 输入法的例子和源代码看了不少时间了,看得头很晕,很郁闷。静下心来把整个代码想了一遍,其实大部分代码都在处理绘制界面,以及事件的处理,

文章标题 使用Chrome来调试你的AndroidApp个人一直对Chrome情有独钟,Chrome除了更快之外,对开发者的支持更友好。内置强大的DeveloperTools,相信Web开发简直爱不释手

标签: Android 水平居中

本文链接地址:https://www.jiuchutong.com/biancheng/376668.html 转载请保留说明!

上一篇:Android 多图片情况下,发生内存溢出的解决办法(android图片库)

下一篇:关于获取本机ip的问题(获取本地ip地址失败)

  • 应纳所得税额的税率
  • 增值税应交税费科目
  • 预包装食品销售流程图
  • 小企业会计准则以前年度损益调整
  • 非营利机构注册要求
  • 印花税的计税依据怎么算公式
  • 股权计税成本如何计算?
  • 研究开发费用加计扣除多少
  • 税率和征收率的含义和区别
  • 水资源税改革试点实施情况
  • 办公室的取暖费怎么做会计分录
  • 没有认证方式
  • 个人房补申请书怎么办
  • 外汇网上申报操作流程图
  • 实收资本的入账金额怎么算
  • 免税和退税的区别出口企业
  • 电子发票逾期未报税怎么办
  • 进口付汇核销流程
  • 合并报表的所得税税率
  • 印花税年度申报表怎么填
  • 子公司是否可以共享总公司的资质
  • 增值税普票当月开错了怎么办
  • 应收账款形成的内部原因和外部原因
  • 公司付股东退股怎么处理
  • 简易计税分包款进项税可以抵扣吗
  • 一般纳税人增值税结转账务处理
  • 交割单会出错吗
  • 收支两条线是指
  • 初级会计实务的心得体会
  • rmb转
  • 计算机怎么设置长亮
  • 搬迁收入税务筹划
  • 商业会计做账
  • 其他应收款的会计处理
  • 投资性房地产出售时其他综合收益
  • 详解金球奖之争
  • 行政事业性收费目录
  • 用人单位垫付生育津贴怎么算
  • 财政补贴是解决什么问题的
  • 微软 gcr
  • win11调节屏幕亮度快捷键
  • php date()
  • 年应税额是怎么算的
  • 中国姓氏英文写法
  • 小规模企业逾期是微信扫码付款吗
  • 稿费演出费等劳务收入算工资吗
  • 个体户个人所得税税率表2023计算
  • 以前年度支出如何计算
  • 个人所得税生产经营所得B表
  • php网站漏洞
  • 怎么开电子专用增值税发票
  • access中宏是按什么调用的
  • 所得税汇算清缴调整项目
  • 获取gridview某行某列的值
  • 预计净残值是怎么算出来的
  • 专项应付款如何记账
  • 员工借款属于什么现金流量
  • 公司临时工的车可以买吗
  • 养老保险产生的利息怎么来的
  • 资产评估资产如何入帐
  • 金税系统怎么填写开票信息
  • 会计报表分析的方法
  • sql删除重复数据只保留一条日期最大的
  • mysqlbinlog -vvv
  • mysql 5.7.18 winx64密码修改
  • 搜索框打开
  • win8系统升级win8.1
  • win10一年更新一次
  • win8无线网络受限 重连又好了
  • unity绘制曲线
  • linux中查看命令怎么使用
  • 置顶句子怎么弄
  • ajax动态加载json数据
  • nodejs获取当前时间
  • vbs以管理员权限运行
  • linux中的tree
  • jQuery简单实现tab选项卡切换效果
  • 现在开票可以不去税务局吗
  • 河北公示信息网
  • 该纳税人还未申报,请申报成功后
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设