ScrollBarPanelWithClock:仿Path滚动条(scrollbar)效果

来自: 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

,只不过它去掉了时钟控件,只是显示提示文字。