2012-02-01 112 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