小小滾動條,設計還是挺復雜。

其中有兩種類型的滾動條,一條是普通的滑動時的滾動條,一種是快速滾動條
項目中曾經就出現過XML定義了 android:scrollbars="none" 但是滑動時,還是會出現
滾動條,其中是因為設置了快速滾動條的原因 android:fastScrollEnabled="true",而默認android:fastScrollEnabled是false的
關于快速滾動條還有最小頁數設置,見FashScroller源碼,當滾動的頁數在4頁之內時,是不會出現快速滾動條的
// 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
代碼設置如下:
//修改快速滾動條圖片
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();
}
另外有需要云服務器可以了解下創新互聯scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
網頁題目:Android滾動條-創新互聯
文章鏈接:http://www.yijiale78.com/article42/pijhc.html
成都網站建設公司_創新互聯,為您提供網站內鏈、外貿建站、網頁設計公司、企業網站制作、靜態網站、網站改版
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯