位置: 编程技术 - 正文

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

  • 计提企业所得税分录
  • 投资款要不要交企业所得税
  • 番茄开发票属于蔬菜吗
  • 专利银行卡汇款流程
  • 月利润报表怎么制作
  • 购买电商平台
  • 投资性房地产账面价值大于公允价值计入什么
  • 企业进行税收筹划
  • 现金支票 差旅费
  • 与成本直接相关的工资怎么会计处理?
  • 调低社保基数怎么操作
  • 什么时候应做资产减值准备?
  • 销售货物并运输增值税
  • 税率为0的增值税发票能抵扣吗
  • 一般贸易免抵退税计算
  • 减免附加税的账户有哪些
  • 境外施工
  • 进项税转出的会计处理
  • 企业所得税怎么征收
  • 收回公司代垫职工款项怎么做凭证?
  • 承兑汇票属于现金支付吗
  • 办公室装修计入什么科目里
  • 可抵扣的金税盘维护费会计分录怎么做?
  • 网络共享每次都要输入密码
  • 不得抵扣的进项税额计入哪里
  • 接入设备检测
  • 基于php开发
  • 苹果电脑隐藏软件功能怎么开启
  • linux系统基础教程
  • 未开票的销售收入分录
  • 没有认缴的股东算是股东?
  • 发票已认证当月未申报怎么办
  • 出差海外
  • 三维目标通用模板
  • 微信第三方登录信息修改
  • 解决跨域问题的注解
  • pytorch1.9.0
  • 小微企业资金数额
  • 主动学习(Active Learning,AL)的理解以及代码流程讲解
  • 子公司借钱给母公司使用
  • 代理记账的业务规范
  • 车间管理人员差旅费
  • 企业非正常损失如何处理
  • 农副产品收购分录
  • 入股投资的钱能取出来吗
  • 付了电费当月没有收到发票
  • 借款收回的会计科目
  • 银行卡被误扣多少钱
  • 外贸企业汇兑损益如何减少
  • 电子承兑汇票做账看哪个日期
  • 土地增值税税率怎么算
  • 会计中的一级科员是什么
  • 股东将股权转让后是否还承担责任
  • 其他应收款如何计提坏账准备
  • 会计核算方法包括
  • 备查账簿有没有固定的格式
  • mysql外键怎么写
  • 史上最全的mysql基础教程
  • windows vista(service pack1)
  • solaris安装软件包
  • linux 多网卡配置
  • new folder.exe是什么
  • 微软win10专业版多少钱
  • win10系统开机桌面图标不见了
  • win7无法远程桌面win10
  • win8磁盘占用率100%如何解决
  • linux we
  • javascript 数字类型
  • LocalBroadcastManager原理和机制
  • shell脚本引用文件
  • python给批量图片添加文字
  • Javascript字符串对象函数
  • express常用api
  • 广东增值税电子普通发票图片
  • 成品油消费税税率包括哪些
  • 存款利息需要交税吗
  • 耕地占用税是土地增值税开发成本吗
  • 暂停资本化期间,一般借款的借款利息不允许资本化
  • 河北省房产评估机构排名
  • 2020年南通居民医保缴费标准
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设