位置: 编程技术 - 正文

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

  • 购买方收取的违约金怎么入账
  • 长期未付款
  • 税务师考试科目安排
  • 缓交的社保费,包括个人部分
  • 网银转账往来款
  • 季报利润总额是填本季度金额还是本年累计数
  • 发票进项和销项差一个字
  • 递延所得税资产计算公式
  • 本年利润期末一般有余额吗
  • 公司外籍人员签证如何办理
  • 在建工程进项税额
  • 年终结账后,应当更换新账的有( )
  • 行政事业单位培训伙食补助报销规定
  • 预缴土地增值税需要计提吗
  • 分公司不独立核算怎么报税
  • 一般纳税人税控盘维护费会计分录
  • 小规模纳税人代账一年多少钱
  • 企业收到财政专项资金账务处理
  • 无法删除文件提示怎么办
  • 负债率是什么指标
  • 多缴的企业所得税如何处理
  • 计提城市维护费分录
  • 高新企业研发费用占销售收入的比例
  • 折旧可以计入主体成本吗
  • mac安装双系统教程
  • 预存500抵扣1000是几折活动?
  • 国有企业上缴利润的账务处理怎么处理?
  • ghost后分区没有了
  • PHP:oci_field_scale()的用法_Oracle函数
  • php保存数据
  • 下列可以作为企业使命
  • 贷记卡怎么还利息
  • 合并及公司利润表
  • 2023年我要实现的目标是
  • 股权转让怎么做凭证分录
  • lspv命令详解
  • dos命令怎么转到d盘
  • 没有发票能办临时牌照吗
  • java一天速成
  • 直接人工成本的计算公式
  • 其他应付款二级明细科目有哪些
  • 固定什么意思
  • 用友t3怎么结转本年利润
  • 出差自己开车去开会怎么报销交通费
  • 其他应付款如何隐藏收入
  • 佣金支出和手续费一样吗
  • 长期待摊费用的最新账务处理
  • 生物资产转让增值税
  • 同一客户有应收应付可以相互抵消吗
  • 工会经费如何申请返还
  • 什么叫社保差额调整
  • 增值税税控系统专用设备费及技术维护费抵扣
  • 如何控制生产成本和利润
  • 增值税稽查补交税会计处理
  • windows8出现蓝屏
  • microsoft window vista
  • Ubuntu 12.04/14.04 LTS版内核更新 修复七个重大安全漏洞
  • centos6.8配置网络
  • fedora系统安装教程
  • 电脑右下角windows设置在哪
  • linux如何修改gid
  • exe文件xp3
  • 电脑xp系统最大多少g
  • win8.1黑屏
  • win7设备管理器里面没有网络适配器
  • linux运行级别有几种
  • 如何搭建环境变量
  • ftp下载怎么用
  • 批处理传输文件夹到ftp
  • html用法
  • opengl纹理错误变成条纹
  • css文本框怎么对齐
  • Linux 中的通配符详解及实例
  • jquery简单例子
  • 增值税红字发票怎么做账
  • 广东税务局一般几点上班
  • 研发材料占研发费用比例超出50%
  • 税收缴款书税务收现专用的开票人是谁
  • 购销合同印花税的计税依据怎么算
  • 铜陵职业技术学院专业
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设