2012-02-01 116 views

回答

0

因此,我結束了在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="vertical" 
    android:background="@color/white" 
    android:id="@+id/splash_linear"> 
    <FrameLayout 
     android:layout_width="144dp" 
     android:layout_height="13dp" 
     android:layout_gravity="center" 
     android:layout_marginTop="20dp"> 
     <View android:id="@+id/progress_horizontal" 
      android:background="@drawable/progress_background" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 
     <View android:id="@+id/progress_horizontal_bar" 
      android:background="@drawable/progress_bar" 
      android:layout_width="0dp" 
      android:layout_height="match_parent"/> 
    </FrameLayout> 
</LinearLayout> 

然後在代碼:

public void updateProgress(int percent) { 
    int progressBarSizeDp = 144; // the size of the progressbar 
    float scale = (float) (progressBarSizeDp/100.0); 
    int progressSize = (int) (percent * scale); 
    if(progressSize > progressBarSizeDp) { 
     progressSize = progressBarSizeDp; 
    } else if(progressSize < 20) { 
     progressSize = 20; 
    } 

    View progressBar = (View) findViewById(R.id.progress_horizontal_bar); 
    int py = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, progressSize, getResources().getDisplayMetrics()); 

    LayoutParams params = new FrameLayout.LayoutParams(py, LayoutParams.MATCH_PARENT); 
    progressBar.setLayoutParams(params); 
    View splashMain = (View) findViewById(R.id.splash_linear); 
    splashMain.invalidate(); 
} 
1

基本上你應該做一個自定義的小工具,所以你可以把它縮小到你的口味。

這裏是關於你正在尋找什麼的教程。 link!

+0

這可能工作,但似乎比需要更復雜。 – Warpzit 2012-02-02 08:55:58