我正在創建一個自定義視圖來表示某種內容。我希望此內容可以滾動(垂直),並且我希望在滾動過程中可以看到標準滾動條。爲了做到這一點,我已經包括下面的代碼到我的自定義視圖的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)
你在哪裏使用25.0dip? –
它被定義在索尼設備上使用的Android版本的標準'themes.xml'文件的深處。由於我無法訪問這些特定的數據,因此我無法確定究竟在哪裏。 –
你能把它從25.0改爲25嗎? –