Android学习—超简单实现带进度ProgressBar滚动条

发布时间:2020-07-02 09:54:10 作者:孤月2012
来源:网络 阅读:3570

思路:想在ProgressBar上显示百分比进度,百度、google搜索一下,满屏都是那个TextProgressBar,我没引用那个,当时觉得应该可以更简单的实现,于是直接就在UI上面尝试,把ProgressBar放在RelativeLayout布局中,并在ProgressBar后面加个TextView,使这两个控件叠加就解决了,下面是xml,可以参考~

效果图:

Android学习—超简单实现带进度ProgressBar滚动条

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();//控件叠加时,显示在最上面,这句很重要

 

推荐阅读:
  1. Android进度条progressbar
  2. android 进度条ProgressBar样式设置

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

进度 android progressbar

上一篇:https浏览器证书是什么

下一篇:linux系统中可以安装哪些软件

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》