SeekBar也玩分段


Android進階之UI深度定制系列(一)

                                       SeekBar也玩分段

       常見的SeekBar和進度條一樣從0-100%之間均可以滑動,但是有時候我希望能把進度粗略的分成幾段,就像RatingBar那樣;下面是大致效果圖:

        <SeekBar
            android:id="@+id/seekBar1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:progress="25"
            android:progressDrawable="@drawable/XXX.png"
            android:thumb="@drawable/yyy.png" />

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:src="@drawable/zzz.png" /> 

重要的屬性android:progressDrawable
這里面android:progressDrawable比較重要,我們可以以此改變滑動塊的外觀
實現上述效果主要是結合代碼,在SeekBar的事件中做相應處理;

分段可以用ImageView覆蓋在SeekBar之上;涉及的方法主要有兩個:
1----->onStopTrackingTouch(SeekBar seekBar)
2----->onProgressChanged(SeekBar seekBar, int progress,boolean fromUser)
在onProgressChanged中根據當前滑動位置,手動設置進度位置;
在onStopTrackingTouch中獲取上一步中設置的進度位置,做個性化顯示操作;

代碼略。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM