位置: 编程技术 - 正文

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地址失败)

  • 资金性质生产性是什么意思
  • 工会经费税前扣除比例是多少
  • 个税系统里的免税收入在哪删除
  • 调整汇算清缴利息怎么算
  • 公租房租金收入什么科目
  • 进项税额转出补交税金会计分录
  • 非独立核算的公司怎么报税
  • 定额发票验旧后还能用吗
  • 职工个人负担的医疗保险可以在计算个人所得税前扣除
  • 增值税附表一免税项目金额填不上
  • 资产负债表和利润表在哪里查
  • 股权转让缴印花税公司用进账吗
  • 银行存款日记账和现金日记账的区别
  • 公司代缴的个税怎么查询
  • 季度收入超过30万但开票只有10万
  • 跨月发票冲红账怎么做
  • 企业对外捐赠现金的会计处理
  • 增值税进项留抵退税的账务处理
  • OS X Yosemite系统下载失败怎么办?OS X 10.10下载错误解决方法
  • 在建工程工程款优先受偿权
  • 收到退回款项
  • sxgdsenu.exe - sxgdsenu是什么进程 有什么用
  • 索尼vpcea200c笔记本
  • nmeo.exe是什么
  • 开启自动备份注册表
  • 劳务派遣公司账目如何做
  • 居民企业境外所得税率
  • 供货商倒闭未缴增值税
  • coco2017数据集介绍
  • 公司基本户可以收款吗
  • Vite4+Pinia2+vue-router4+ElmentPlus搭建Vue3项目(组件、图标等按需引入)[保姆级]
  • 中兴网管操作手册
  • 休产假期间社保个人部分怎么办
  • 海外佣金需要交税吗
  • 以股权换股权税务问题
  • 收入少收钱账务处理
  • sql有什么
  • 织梦模板首页logo修改
  • 减免增值税要计入营业外收入
  • sqlserver 数据集字符集种类
  • 食堂费用没有发票
  • 车辆保险费用查询
  • 记账凭证后面附什么原始凭证
  • 普通发票为什么只能领一张
  • 长期股权投资损益调整是什么意思
  • 工程中标费用放哪个科目
  • 机物料消耗计入什么费用
  • 职工福利费如何计提
  • 购货方尚未偿付的货款属于什么会计科目
  • 自产自销免税发票可以抵税吗
  • 发生额怎么计算
  • 啥叫合同
  • 餐饮怎么扣税
  • 会计成本核算方法有几种类型
  • 什么是逐步结转分步法
  • win7系统打开软件就停止工作
  • 不重装系统怎么修复
  • linux rpm包安装
  • mac如何关闭开机密码
  • windows8.1关闭开机密码
  • windows 10移动版
  • linux定时任务实现原理
  • linux监控软件zabbix
  • win7网络正常但是所有浏览器网页打不开
  • 升级win10后东西还在吗
  • windows10窗口设置在哪
  • cocos2dx tableview基础:实现多图片的滑动显示
  • 图形学实验报告总结
  • js 读取 excel
  • 微信小程序实现查询功能
  • javascript中数组
  • 批处理命令读取文件内容
  • android网络访问异常提示有哪些
  • JavaScript onkeydown事件入门实例(键盘某个按键被按下)
  • 新疆12366电子税务局官网手机版
  • 2021辽宁粮食直补
  • 福建省国税局官网
  • 辽宁交管12123能用微信支付吗
  • 完税凭证验证码
  • 个人所得税怎么填写子女教育
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设