位置: 编程技术 - 正文

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

  • 固定资产可以一次性摊销吗
  • 产品成本计算的基本方法和辅助方法的划分标准是
  • 企业所得税季度申报表A类
  • 印花税申报减免额不能为0怎么报
  • 房地产开发企业预缴增值税
  • 挖掘机要交多少个人所得税
  • 农产品为什么价格低
  • 耕地占用税滞纳金是否能减免
  • 库存商品进项税额转出分录怎么写
  • 个人所得税退税多久到账
  • 砂石建筑材料验收规范
  • 企业劳务发票怎么开,税率是多少
  • 电商平台小规模纳税标准
  • 红包营销活动方案
  • 广告费和业务宣传费扣除标准2023
  • 票据再质押
  • 应收款计提
  • 分包开普通发票还是增值税专用发票?
  • 按简易办法征收增值税
  • 金蝶软件测试笔试题及答案
  • linux虚拟机怎么输入中文
  • 个人所得税跨年度能退吗
  • 权益净利率是什么意思啊
  • svchost程序错误怎么修复
  • 华为手机开热点后wlan自动关闭
  • 公司社保钱可以套出来吗
  • 分手我不怕
  • php中unlink
  • 软件开发企业进项税额抵扣
  • 偿还债券本金和利息
  • 解决城市内涝的题目
  • 餐饮费是业务招待费还是差旅费
  • openai.error.AuthenticationError: No API key provided.
  • 智能优化算法主要内容
  • 网上学电脑的软件
  • 收到借款时 会计科目怎么做
  • 债券溢折价摊销
  • 被投资的公司注销后投资公司怎么处理
  • 非居民纳税人工资个人所得税税率
  • vue打包找不到文件
  • 进项税需要转出的分录
  • 什么发票可以抵扣增值税吗
  • 应交增值税进项税额
  • 劳务费发票是个人的吗
  • excel内账报表
  • 管理费用 暂估入账
  • 公司从异地迁移到本地怎么向当地政府写申请
  • 收到返还工会经费大于管理费用
  • 财产租赁合同印花税率多少
  • 税务局手续费返还什么时间到账
  • 应收账款可能出现贷方余额吗
  • 从国外进口一批原材料,海关核定的关税完税价
  • 一般纳税人注销公司流程2023
  • 成本暂估入帐如何做分录
  • 应收账款周转天数越大说明什么
  • 会计审核外来凭证怎么做
  • 如何防止mysql数据库攻击
  • sql数据库建立步骤
  • 如何进行节约
  • freebsd wifi设置
  • 苹果7开发者模式怎么打开
  • solaris配置ip地址
  • os x10.11el capitan公测版下载地址(公测版计划注册教程)
  • mac如何全屏窗口
  • win7的wifi功能在哪
  • win8.1 应用商店是不是不能用了
  • win10系统onenote不能用
  • 解决出现的问题下一句,欢迎的语气
  • perl 删除文件
  • jquery的实现原理
  • perl $?
  • java的gui框架
  • c#的程序集
  • 简述jquery的优势
  • Android调用系统的电话拨号程序
  • 北京930末班车时间表
  • 金税盘软件怎么打开
  • 金银首饰以旧换新业务按销售方实际
  • 1国家税务总局
  • 如何查公司税务问题
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设