位置: 编程技术 - 正文

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

  • 文化事业建设费征收对象
  • 公司优秀党员事迹材料
  • 管道燃气工程设计方案
  • 个税申报缴费
  • 注册公司认缴资本不缴可以吗
  • 联营企业股利收入
  • 退税 增值税
  • 汇算清缴补交所得税会计分录小企业会计政策
  • 企业增资扩股如何办理
  • 造价服务费收费标准计算器
  • 系统技术维护费计入什么科目
  • 餐饮店投资入股注意事项
  • 补偿款开具发票
  • 增值税专用发票和普通发票的区别
  • 设备安装和设备出售的税率一样吗
  • 增值税可以不计提,直接缴纳吗
  • 金税四期再出新公告
  • 外购库存商品
  • 净利润怎么计入所有者权益
  • 营改增之前的增值税
  • 办理企业土地证要多少钱
  • 经营所得的含义
  • linux怎么开启远程
  • 跨年度增值税发票作废怎么退税
  • 炫龙笔记本win10系统为什么没有关闭触控板
  • win7怎么删除windows.old
  • javascript移动鼠标
  • 卡比托丽娜·瓦西里耶娃
  • pytorch1.5
  • 利用Linux Find命令查找文件方法记录 快速查找文件位置
  • php发送http请求的常用方法分析
  • php 路由实现
  • 计入固定资产的条件
  • 固定资产清理如何申报增值税
  • php是免费的吗
  • python中assert()函数
  • python之sqlalchemy创建表的实例详解
  • 阿里云安装centos8
  • 外经证是啥样
  • 建账的三个基本步骤
  • 火车票报销抵扣比例是多少
  • 无形资产达到可使用状态前如何入账
  • 事业单位大型修缮与办公用房维修费区别
  • 计量差错引起的原材料盘亏
  • 股票质押式回购交易是什么意思
  • 转让土地及地上建筑物涉及的税金
  • 营改增适用范围
  • 临时账户名称是什么意思
  • 目前哪些费用不能抵扣
  • 预收账款的金额是什么
  • 水果销售公司怎么起名字好听
  • 准备金支出是否含税
  • 年终结账的会计分录
  • 建账是啥意思
  • mysql数据源
  • mysql5.7.24安装配置教程
  • win7 光盘
  • Linux配置防火墙端口
  • xp系统内存不能为read的解决方法
  • win7安全模式
  • win8.1系统补丁
  • Extjs4.0 ComboBox如何实现三级联动
  • node.js编译
  • cocos2dx入门
  • 批处理文件夹内文件名
  • android 蓝牙 驱动 适配 sdio rk
  • shell字符串比较相等
  • js的异步解决方案有哪些
  • 怎么配置nodejs的环境
  • js 引用类型
  • div跟随滚动条移动
  • 重庆车辆检测费多少钱
  • 青岛市市南区税务局第一税务所
  • 广东省国家税务总局电子税务局
  • 2008土地管理办法
  • 中国税务报订阅电话
  • 天津市税务机关代码
  • 河北地税网上申报纳税
  • 北京市税务局热搜
  • 福建高速公路电子发票怎么开
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设