2011-06-14 76 views
1

我想創建一個進度條,當增加時會自動向上滑動。我已經對滑動位進行了排序(使用java),但現在想要創建一個自定義進度條組件。這是我到目前爲止有:Android自定義進度條組件

public class Smooth_Progress_Bar extends ProgressBar{ 

public Smooth_Progress_Bar(Context context) { 
    super(context); 
    } 
} 

我使用這個XML代碼:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 

<com.todddavies.content.smoothprogressbar.Smooth_Progress_Bar 
    android:layout_width="fill_parent" 
    style="@android:style/Widget.ProgressBar.Horizontal" 
    android:layout_height="50dp" 
    android:layout_marginBottom="5dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp" 
    android:progressDrawable="@drawable/pb"/> 

</LinearLayout> 

我親近的直接動力:/

我強烈懷疑我在做什麼java比特大錯了。我保證打出正確的答案!

+0

你可以發佈從LogCat獲得的堆棧跟蹤嗎? – kabuko 2011-06-14 20:33:18

回答

2

我用你的代碼做了一個項目,代碼完全相同(甚至對象名稱爲「Smooth_Progress_Bar」)。
它全部編譯並運行良好。 因此,這讓:

您可能需要三個構造函數,例如:

public Smooth_Progress_Bar(Context context) { 
    super(context); 
} 
public Smooth_Progress_Bar(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 
public Smooth_Progress_Bar(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
} 

或你的問題是在你的progressDrawable。如果drawable是xml,則可能包含錯誤。嘗試構造函數,如果這不起作用,請檢查您的drawable。

+0

他不需要全部三個。他只需要具有AttributteSet參數的兩個構造函數之一。 – AedonEtLIRA 2011-06-14 21:53:19

+0

確實 - 我正在懶惰。中間的人會這樣做。 – 2011-06-14 22:08:23