Android进度条(星级评分)使用详解(二)
public class MainActivity extends ActionBarActivity { private ImageView image = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); image = (ImageView)findViewById(R.id.image); SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar); seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { //当拖动条发生改变时触发该方法 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { //Notification that the progress level has changed image.setImageAlpha(progress);//动态改变图片的透明度 } public void onStopTrackingTouch(SeekBar seekBar) { //Notification that the user has finished a touch gesture } public void onStartTrackingTouch(SeekBar seekBar) { //Notification that the user has started a touch gesture } }); } }
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ImageView android:id="@+id/image" android:layout_width="fill_parent" android:layout_height="250dp" android:src="@drawable/hehe"/> <!--定义一个拖动条,并改变它的滑块外观 --> <SeekBar android:id="@+id/seekBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="255" //设置拖动条的最大值 android:progress="255" //设置拖动条当前默认值 android:thumb="@drawable/android" /> </LinearLayout>
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); image = (ImageView) findViewById(R.id.image); RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar); ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() { public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { image.setImageAlpha((int)(rating*255)/5);// 动态改变图片的透明度 } });
<RatingBar android:id="@+id/ratingBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:max="255" android:numStars="5" android:stepSize="0.5" android:progress="255"/>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。