思路:想在ProgressBar上显示百分比进度,百度、google搜索一下,满屏都是那个TextProgressBar,我没引用那个,当时觉得应该可以更简单的实现,于是直接就在UI上面尝试,把ProgressBar放在RelativeLayout布局中,并在ProgressBar后面加个TextView,使这两个控件叠加就解决了,下面是xml,可以参考~
创新互联专注于企业营销型网站建设、网站重做改版、临邑网站定制设计、自适应品牌网站建设、H5响应式网站、商城网站开发、集团公司官网建设、外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为临邑等各大城市提供网站开发制作服务。效果图:
XML:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:layout_gravity="center" android:background="#FFFFFF"> <TextView android:id="@+id/tvGraphType" android:layout_width="84dp" android:layout_height="wrap_content" android:padding="2sp" android:gravity="right" android:maxLength="6" android:textColor="#666666" android:text="type" android:textSize="13sp"/> <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <ProgressBar android:id="@+id/pbGraph" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="right" android:padding="2sp" android:progressDrawable="@drawable/pbarcolor_out" android:layout_marginLeft="4dp" android:layout_marginRight="4dp" android:layout_marginBottom="4dp"/> <TextView android:id="@+id/tvGraphPercent" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:textColor="#666666" android:text="%" android:textSize="13sp"/> </RelativeLayout> </LinearLayout>
进度条上百分比进度的计算也贴一下吧:
//pbOuts 是ProgressBar,outPercent 是用于显示百分比的TextView holder.pbOuts.setMax(Graph.getRound(Maxout)); holder.pbOuts.setProgress(Graph.getRound(Outcomes)); if (Maxout>0) { holder.outPercent.setText(String.valueOf(Graph.getRound((Outcomes*100/Maxout)))+"%"); }else { holder.outPercent.setText("0%"); } holder.outPercent.bringToFront();//控件叠加时,显示在最上面,这句很重要
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
分享文章:Android学习—超简单实现带进度ProgressBar滚动条-创新互联
当前地址:https://www.cdcxhl.com/article22/ccchjc.html
成都网站建设公司_创新互联,为您提供Google、网站营销、电子商务、营销型网站建设、网站建设、网站收录
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联