十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊
量身定制 + 運營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
小小滾動條,設(shè)計還是挺復(fù)雜。
其中有兩種類型的滾動條,一條是普通的滑動時的滾動條,一種是快速滾動條
項目中曾經(jīng)就出現(xiàn)過XML定義了 android:scrollbars="none" 但是滑動時,還是會出現(xiàn)
滾動條,其中是因為設(shè)置了快速滾動條的原因 android:fastScrollEnabled="true",而默認(rèn)android:fastScrollEnabled是false的
關(guān)于快速滾動條還有最小頁數(shù)設(shè)置,見FashScroller源碼,當(dāng)滾動的頁數(shù)在4頁之內(nèi)時,是不會出現(xiàn)快速滾動條的
// Minimum number of pages to justify showing a fast scroll thumb
private static int MIN_PAGES = 4;
以及:
// Are there enough pages to require fast scroll? Recompute only if total count changes
if (mItemCount != totalItemCount && visibleItemCount > 0) {
mItemCount = totalItemCount;
mLongList = mItemCount / visibleItemCount >= MIN_PAGES;
}
還有就是有時可能要自定義滾動條的圖片
XML定義如下:
android:scrollbarThumbVertical
android:scrollbarThumbHorizontal
代碼設(shè)置如下:
//修改快速滾動條圖片
try {
Field f = AbsListView.class.getDeclaredField("mFastScroller");
f.setAccessible(true);
Object o = f.get(this);
f = f.getType().getDeclaredField("mThumbDrawable");
f.setAccessible(true);
Drawable drawable = (Drawable) f.get(o);
drawable = getResources().getDrawable(R.drawable.icon);
f.set(o, drawable);
} catch (Exception e) {
e.printStackTrace();
}
//修改豎向滾動條圖片
try {
Field f = View.class.getDeclaredField("mScrollCache");
f.setAccessible(true);
Object scrollabilityCache = f.get(this);
f = f.getType().getDeclaredField("scrollBar");
f.setAccessible(true);
Object scrollBarDrawable = f.get(scrollabilityCache);
f = f.getType().getDeclaredField("mVerticalThumb");
f.setAccessible(true);
Drawable drawable = (Drawable) f.get(scrollBarDrawable);
drawable = getResources().getDrawable(R.drawable.rating_progress);
f.set(scrollBarDrawable, drawable);
} catch (Exception e) {
e.printStackTrace();
}
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。