2014-02-20 52 views
0

我正在創建一個自定義視圖來表示某種內容。我希望此內容可以滾動(垂直),並且我希望在滾動過程中可以看到標準滾動條。爲了做到這一點,我已經包括下面的代碼到我的自定義視圖的cinstructor:android:索尼Xperia:滾動條自定義視圖

setVerticalScrollBarEnabled(true); 
setHorizontalScrollBarEnabled(false); 
TypedArray a = context.obtainStyledAttributes(R.styleable.View); 
initializeScrollbars(a); 
a.recycle(); 

現在,這個R.stylable.View如下:

<declare-styleable name="View"> 
    <attr name="android:fadeScrollbars"/> 
    <attr name="android:scrollbarAlwaysDrawHorizontalTrack"/> 
    <attr name="android:scrollbarAlwaysDrawVerticalTrack"/> 
    <attr name="android:scrollbarDefaultDelayBeforeFade"/> 
    <attr name="android:scrollbarFadeDuration"/> 
    <attr name="android:scrollbarSize"/> 
    <attr name="android:scrollbarStyle"/> 
    <attr name="android:scrollbarThumbHorizontal"/> 
    <attr name="android:scrollbarThumbVertical"/> 
    <attr name="android:scrollbarTrackHorizontal"/> 
    <attr name="android:scrollbarTrackVertical"/> 
    <attr name="android:scrollbars"/> 
</declare-styleable> 

此代碼正常工作對每一個Android設備。除索尼XPERIAž使我有NumberFormatException每次遇到initializeScrollbars(a)時間:

Caused by: java.lang.NumberFormatException: Invalid int: "25.0dip" 
at java.lang.Integer.invalidInt(Integer.java:138) 
at java.lang.Integer.parse(Integer.java:375) 
at java.lang.Integer.parseInt(Integer.java:366) 
at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:122) 
at android.content.res.TypedArray.getInt(TypedArray.java:254) 
at android.view.View.initializeScrollbars(View.java:4172) 
at TheCustomViewIAmTryingToCreate.<init>(MyCustomView.java:164) 
... 36 more 

我可以看到,它錯誤地解釋了一些XML定義的值,但我不能讓哪一個確切。這條線:

at android.view.View.initializeScrollbars(View.java:4172) 

點我View類的來源,我爲了找到原因審查。問題是initializeScrollbars方法(官方Android源碼)與無關。 Obviuosly索尼(以某種方式)在他們的設備上修改了Android,現在讓我的代碼崩潰了。

有沒有人知道是什麼原因造成這樣的問題,或者我在哪裏可以找到Android的安裝源Xperia Z1(C6903)來看看這個問題的原因?

編輯:這也發生在的Xperia平板Z(SGP321)的Xperia ZL(C6503)

+0

你在哪裏使用25.0dip? –

+0

它被定義在索尼設備上使用的Android版本的標準'themes.xml'文件的深處。由於我無法訪問這些特定的數據,因此我無法確定究竟在哪裏。 –

+0

你能把它從25.0改爲25嗎? –

回答

0

我還是不知道是什麼原因導致這種崩潰,但我設法解決它。我結束了一些更多的屬性擴展R.stylable.View

<declare-styleable name="View"> 
    <attr name="android:background"/> 
    <attr name="android:clickable"/> 
    <attr name="android:contentDescription"/> 
    <attr name="android:drawingCacheQuality"/> 
    <attr name="android:duplicateParentState"/> 
    <attr name="android:fadeScrollbars"/> 
    <attr name="android:fadingEdge"/> 
    <attr name="android:fadingEdgeLength"/> 
    <attr name="android:fitsSystemWindows"/> 
    <attr name="android:focusable"/> 
    <attr name="android:focusableInTouchMode"/> 
    <attr name="android:hapticFeedbackEnabled"/> 
    <attr name="android:id"/> 
    <attr name="android:isScrollContainer"/> 
    <attr name="android:keepScreenOn"/> 
    <attr name="android:longClickable"/> 
    <attr name="android:minHeight"/> 
    <attr name="android:minWidth"/> 
    <attr name="android:nextFocusDown"/> 
    <attr name="android:nextFocusLeft"/> 
    <attr name="android:nextFocusRight"/> 
    <attr name="android:nextFocusUp"/> 
    <attr name="android:onClick"/> 
    <attr name="android:padding"/> 
    <attr name="android:paddingBottom"/> 
    <attr name="android:paddingLeft"/> 
    <attr name="android:paddingRight"/> 
    <attr name="android:paddingTop"/> 
    <attr name="android:saveEnabled"/> 
    <attr name="android:scrollX"/> 
    <attr name="android:scrollY"/> 
    <attr name="android:scrollbarAlwaysDrawHorizontalTrack"/> 
    <attr name="android:scrollbarAlwaysDrawVerticalTrack"/> 
    <attr name="android:scrollbarDefaultDelayBeforeFade"/> 
    <attr name="android:scrollbarFadeDuration"/> 
    <attr name="android:scrollbarSize"/> 
    <attr name="android:scrollbarStyle"/> 
    <attr name="android:scrollbarThumbHorizontal"/> 
    <attr name="android:scrollbarThumbVertical"/> 
    <attr name="android:scrollbarTrackHorizontal"/> 
    <attr name="android:scrollbarTrackVertical"/> 
    <attr name="android:scrollbars"/> 
    <attr name="android:soundEffectsEnabled"/> 
    <attr name="android:tag"/> 
    <attr name="android:visibility"/> 
</declare-styleable> 

這也許是太多了,但之後我的應用程序不再崩潰。

雖然沒有必要,但如果有人對我出錯的地方有任何想法,請不要讓我失望。