ScrollBarPanelWithClock:仿Path滾動條(scrollbar)效果

nedurewqehe218 8年前發布 | 7K 次閱讀 Android開發 移動開發

來自: http://www.jcodecraeer.com//a/anzhuokaifa/androidkaifa/2014/0814/1648.html


Path應用中scrollbar是一個帶有時鐘的矩形控件,隨著listview的滾動scrollbar的數字和始終都會相應的發生改變。ScrollBarPanelWithClock實現了和path相同的功能,不過界面稍微簡陋些。

ScrollBarPanelWithClock項目地址:https://github.com/learnNcode/ScrollBarPanelWithClock

用法:

xml

<com.learnNcode.android.ExtendedListView
    xmlns:clock="http://schemas.android.com/apk/res-auto"
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:choiceMode="singleChoice"
    clock:hand_second="@drawable/ic_timer_clock_minute_hand"
    clock:scrollBarPanel="@layout/scrollbarpanel"
    clock:scrollBarPanelInAnimation="@anim/in"
    clock:scrollBarPanelOutAnimation="@anim/out" />

activity中

ExtendedListView mListView = (ExtendedListView) findViewById(android.R.id.list);

listview滾動回調

mListView.setOnPositionChangedListener(new OnPositionChangedListener() {
    @Override
    public void onPositionChanged(ExtendedListView listView, int firstVisiblePosition, View scrollBarPanel) {
         Clock analogClockInstance = (Clock) scrollBarPanel.findViewById(R.id.analogClockScroller);
        Time time = new Time();
        analogClockInstance.setSecondHandVisibility(true);  // to visible second hand
        time.set(position+3, position, 5, 0, 0, 0);
        analogClockInstance.onTimeChanged(time);
        }
    }

可以在OnPositionChanged中初始化clock控件

Time timeObj = new Time();
analogClockObj.setSecondHandVisibility(true);
analogClockObj.setVisibility(View.VISIBLE);
timeObj.set(position+3, position, 5, 0, 0, 0); //pass respective values to the clock here.
analogClockObj.onTimeChanged(timeObj);

你可以設置是否顯示時鐘:

analogClockObj.setVisibility(View.VISIBLE);

還可以設置是否顯示時鐘的第二指針:

analogClockObj.setSecondHandVisibility(true);


github上還有一個實現了相同效果的開源庫Android-ScrollBarPanel,地址https://github.com/rno/Android-ScrollBarPanel,不過Android-ScrollBarPanel大部分代碼好像是copy ScrollBarPanelWithClock

,只不過它去掉了時鐘控件,只是顯示提示文字。

 本文由用戶 nedurewqehe218 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!