Android學習—超簡單實現帶進度ProgressBar捲軸

來源:互聯網
上載者:User

標籤:android   progressbar   

思路:想在ProgressBar上顯示百分比進度,百度、google搜尋一下,滿屏都是那個TextProgressBar,我沒引用那個,當時覺得應該可以更簡單的實現,於是直接就在UI上面嘗試,把ProgressBar放在RelativeLayout布局中,並在ProgressBar後面加個TextView,使這兩個控制項疊加就解決了,下面是xml,可以參考~

650) this.width=650;" title="QQ圖片20150316150605.png" alt="wKioL1UGghyRzq2zAABW3FfcjPA002.jpg" src="http://s3.51cto.com/wyfs02/M01/5B/52/wKioL1UGghyRzq2zAABW3FfcjPA002.jpg" />

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"             style="?android:attr/progressBarStyleHorizontal"             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();//控制項疊加時,顯示在最上面,這句很重要

 

本文出自 “QYtag (Upspringing)” 部落格,請務必保留此出處http://qytag.blog.51cto.com/6125308/1621117

Android學習—超簡單實現帶進度ProgressBar捲軸

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.