位置: 编程技术 - 正文

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

  • 车船税税金及附加计入管理费用嘛
  • 为员工代缴社保材料
  • 增值税电子普通发票怎么作废
  • 短期借款现金流
  • 企业的培训费会计分录
  • 劳务费发票是个人开还是公司开
  • 调研费包括哪些科目
  • 水利建设基金的计税依据
  • 折扣优惠 印花税也是折扣缴纳吗
  • 借方应付账款 贷方银行存款
  • 税收优惠有哪些类型
  • 收到土地使用权转让金会计分录
  • 现金折扣不考虑增值税什么意思
  • 混搭销售的企业有哪些
  • 大家怎么看恒大品牌
  • 销售方退款回来要怎么处理?
  • 计提劳务成本月末需要结转吗
  • 费用收入结转本年利润
  • 计划成本法下会计分录
  • 收到红字发票会计处理
  • 印花税缴纳后合计怎么算
  • 企业交城建税的分录
  • 核定征收的企业需要汇算清缴吗
  • 已认证的发票如何冲红
  • 房地产公司销售自建房怎么纳税
  • 金蝶年结后发现错误怎么办
  • 分支机构能否随总机构认定为一般纳税人
  • 电商平台名称怎么注册
  • 物业税额
  • 企业所得税税率表2023年最新
  • 开立银行承兑汇票清单怎么盖章
  • 员工垫付费用多久报销合理
  • 笔记本恢复出厂设置后和新的一样吗
  • 被替换的账面价值题目
  • 进项税转出怎么填报表
  • 医疗机构医疗服务自查报告怎么写
  • 国企收到财政补贴
  • 小白学php需要多久能上手
  • linux-base
  • php cgi
  • 建筑安装发票可以外地开吗
  • uniapp 信息推送
  • php 输出
  • 金蝶存货核算不能结账,能强制结账吗
  • 服装、眼镜、鞋、西药的发票怎么样做账比较好
  • 一般纳税人进项大于销项账务处理
  • 坏账核销会计处理
  • 最新个人捐款是什么意思
  • 哪些进项税额不能抵扣
  • 建筑公司算不算企业
  • 网站维护费用
  • 研发部门的房租可以资本化
  • 用承兑付货款怎么做会计
  • 非房产企业出售土地,能否计算抵减地价款
  • 利润表持续经营净利润怎么算
  • 无发票 入账
  • 银行本票具体操作流程
  • 学会整理内容
  • ubuntu怎么设置开机自启动程序
  • linux文本处理常用命令
  • ios8.4.1完美越狱教程
  • macair蓝牙用不了
  • 电脑win7一开机就弹出各种广告窗口怎么办
  • win10地图不显示
  • windows 10预览版
  • How to embed a jframe in an eclipse view
  • 批处理注册reg文件
  • js中的date函数
  • linux写时复制
  • hover在jquery中的用法
  • unity data
  • W3C Group的JavaScript1.8 新特性介绍
  • zabbix 微信
  • javascript 日期运算
  • python中函数的功能及作用
  • 贵州网上税务局官网登录
  • 常州的居民医保在哪里交
  • 上海川沙十八铺市场
  • 网上查询公司营业执照
  • 广东省电子税务局申报缴税操作指引
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设