位置: 编程技术 - 正文

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

  • 咨询公司要交税吗
  • 无偿调入固定资产计提折旧吗
  • 发票丢失了能开红字发票吗
  • 跨年度冲红的账务处理
  • 递延收益怎么交企业所得税
  • 经营范围预付卡是什么
  • 工会经费免征三年需要申报吗
  • 营改增后转让土地使用权交什么税
  • 餐饮企业原材料四大类
  • 资产报废变现收入应开具哪种发票
  • 税务局代开的劳务费发票可以入账吗
  • 营改增后销售不动产的收入
  • 房地产企业销售现房是否预缴增值税
  • 年末结转本年利润是在结转损益前还是后
  • 土地租金及青苗赔偿款怎么做账?
  • 同一客户应收应付可以相互抵消吗
  • 所得税汇算清缴调整项目
  • 补贴属于什么手段
  • 小微企业核定征收所得税税率
  • 货物分批付款会计处理
  • 公司账户转私账
  • 研发企业税率
  • 为什么要结转成本差异
  • 未开票收入必须全部转开票收入吗为什么
  • 出口押汇和议付的区别
  • 减免的附加税要计税吗
  • 设备安装服务费税收分类编码
  • 本月无生产,有折旧怎么办
  • PHP:pg_transaction_status()的用法_PostgreSQL函数
  • 固定资产抵债交不交增值税
  • windows11更新多大
  • PHP:pcntl_wtermsig()的用法_PCNTL函数
  • 购入固定资产的会计处理
  • 外购商品转为自用洧费税计算
  • yolov5模型中git的作用
  • laravel视频教程
  • 承担客户车辆维修责任
  • 单文件php文件列表
  • laravel 实例
  • element插件安装方法
  • 关于非营利组织企业所得税免税收入问题的通知
  • 进项税额在借方是增加还是减少
  • 已勾选未确认怎么取消
  • python中列表的索引用法
  • 免税农产品有哪些类型
  • 增值税纳税申报实训报告
  • 工资不纳税项目
  • 增值税要计入应收账款吗
  • 企业固定资产如何查询
  • sql server2014教程
  • mysql5.7版本安装教程
  • 房屋租赁税缴纳时间
  • 年底计提坏账收回一部分怎么处理
  • 资本公积溢价转增
  • 折旧与摊销会计分录
  • 暂估入库的商品怎么做账
  • 进项税额转出的几种情况
  • 计提固定资产折旧怎么做会计科目
  • 注册资金未缴齐怎么处理
  • 品种法案例分析
  • 因进出口商品引起的收支
  • 待摊费用是什么意思
  • 个人到税务局开普票要交多少税
  • 怎么用老毛桃u盘装win7系统 老毛桃u盘装win7系统教程图解
  • xp系统如何删除用户
  • mac无法开机怎么办
  • qtask.exe - qtask是什么进程 有什么用
  • gacrunner.exe是什么
  • linux中grep命令用法
  • win8右边栏设置
  • win10系统下怎么将腾讯qlv格式转换mp4格式?
  • nodejs的应用场景和优缺点
  • 超级硬盘数据恢复软件v2.7
  • jquery校验form表单
  • jQuery ajax MD5实现用户注册即时验证功能
  • javascript操作文件
  • jquery3.6
  • call和apply用法
  • jquery使用教程
  • 资源税条例实施细则
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设