android的seekBar小技巧(评分星级的拖动效果)

来源:互联网 发布:黄金k线图软件 编辑:程序博客网 时间:2024/06/10 14:41

最近遇到一个问题,因为是新人嘛,项目赶工也比较近,所以老是在加班,把平时工作中遇到的问题统一整理,待到双休加班的时候,偷闲发表一下。进入正题:我们经常要用到星级评论的效果,但好像android原声的也不是特别好,最近需要一个效果,可以拖动评分,没有半颗星的,所以我就用seekBar简化了一下,也是一个小技巧了...

<SeekBar                android:id="@+id/sekbar"                android:layout_width="@dimen/dp740"                android:layout_height="@dimen/dp130"                android:layout_centerHorizontal="true"                android:background="@raw/mark3"                android:max="100"                android:progress="100"                android:progressDrawable="@null"                android:thumb="@null"                android:thumbOffset="@null"                android:visibility="visible" />

seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}@Overridepublic void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {if ( progress>= 0 && progress <20 ){score = 1.0f;seekBar.setBackgroundResource(R.raw.mark1);}else if( progress>= 20 && progress <40 ){score = 2.0f;seekBar.setBackgroundResource(R.raw.mark2);}else if( progress>= 40 && progress <60 ){score = 3.0f;seekBar.setBackgroundResource(R.raw.mark3);}else if( progress>= 60 && progress <80 ){score = 4.0f;seekBar.setBackgroundResource(R.raw.mark4);}else if( progress>= 80 && progress <100 ){score = 5.0f;seekBar.setBackgroundResource(R.raw.mark5);}}});

这样的话,你就可以拖动点击的时候随便换张星级的图片了,很好用的哦..


0 0
原创粉丝点击