• ProgressBar 进度条设置百分比显示


    rawable/progressbar

     1 <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
     2 
     3     <item android:id="@android:id/secondaryProgress">
     4         <clip>
     5             <shape>
     6                 <corners android:radius="5dip" />
     7                 <gradient
     8                     android:angle="0"
     9                     android:centerColor="#80ffb600"
    10                     android:centerY="0.75"
    11                     android:endColor="#a0ffcb00"
    12                     android:startColor="#80ffd300" />
    13             </shape>
    14         </clip>
    15     </item>
    16     <item android:id="@android:id/progress">
    17         <clip>
    18             <shape>
    19                 <corners android:radius="5dip" />
    20                 <gradient
    21                     android:angle="0"
    22                     android:endColor="#8000ff00"
    23                     android:startColor="#80ff0000" />
    24             </shape>
    25         </clip>
    26     </item>
    27 
    28 </layer-list>
     1 <ProgressBar
     2         android:id="@+id/ProgressBar"
     3         style="?android:attr/progressBarStyleHorizontal"
     4         android:layout_width="fill_parent"
     5         android:layout_height="5dp"
     6         android:layout_marginLeft="20dp"
     7         android:layout_marginRight="30dp"
     8         android:layout_marginTop="5dp"
     9         android:max="100"
    10         android:progressDrawable="@drawable/progressbar" />
     1       @Override
     2     public View getView(int position, View convertView, ViewGroup parent) {
     3         ChildHolder childHolder = null;
     4         if(convertView == null){
     5             childHolder = new ChildHolder();
     6             convertView = View.inflate(mcontext, R.layout.item_chat, null);
     7             childHolder.ProgressBar = (ProgressBar) convertView.findViewById(R.id.ProgressBar);
     8             convertView.setTag(childHolder);
     9         }else {
    10             childHolder = (ChildHolder) convertView.getTag();
    11         }
    12         // RecordObj 实体对象
    13         RecordObj rd = mlist.get(position);
    14         
    15         int total_count = 0;
    16         for (int i = 0; i < mlist.size(); i++) {
    17             int count = mlist.get(i).getCount();
    18             total_count += count;
    19         }
    20         DecimalFormat df1 = new DecimalFormat("0.0000");  
    21         String str_percent = df1.format((float)rd.getCount() / total_count);
    22         float percent =Float.parseFloat(str_percent) * 100;
    23         DecimalFormat df2 = new DecimalFormat("0.00");
    24         String percents = df2.format(percent) + "%";
    25         int value = childHolder.ProgressBar.getProgress();
    26         if (value == 0) {
    27             doProgress(percent , childHolder.ProgressBar);
    28         } else {
    29             childHolder.ProgressBar.setProgress((int)percent);
    30         }
    31         return convertView;
    32     }
  • 相关阅读:
    qt中使用dll库的方法
    41. wait notify 方法
    40.方式二的练习
    39.线程的实现方式二
    38. 死锁
    37. 解决线程问题方式二(同步函数)
    36. 解决线程问题方式一(同步代码块synchronized)
    35.线程问题
    34. Thread类的常用方法
    33. 自定义线程
  • 原文地址:https://www.cnblogs.com/androidsj/p/4800321.html
Copyright © 2020-2023  润新知