小小滾動條,設(shè)計還是挺復(fù)雜。

成都創(chuàng)新互聯(lián)公司網(wǎng)站建設(shè)公司一直秉承“誠信做人,踏實做事”的原則,不欺瞞客戶,是我們最起碼的底線! 以服務(wù)為基礎(chǔ),以質(zhì)量求生存,以技術(shù)求發(fā)展,成交一個客戶多一個朋友!專注中小微企業(yè)官網(wǎng)定制,網(wǎng)站設(shè)計制作、成都網(wǎng)站設(shè)計,塑造企業(yè)網(wǎng)絡(luò)形象打造互聯(lián)網(wǎng)企業(yè)效應(yīng)。
其中有兩種類型的滾動條,一條是普通的滑動時的滾動條,一種是快速滾動條
項目中曾經(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();
}
新聞標(biāo)題:Android滾動條
標(biāo)題網(wǎng)址:http://www.chinadenli.net/article0/isjpio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、營銷型網(wǎng)站建設(shè)、全網(wǎng)營銷推廣、靜態(tài)網(wǎng)站、建站公司、做網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)