本文共 2248 字,大约阅读时间需要 7 分钟。
1.布局
17 8 13 14 21 22 30 31
2.逻辑控制
1 package com.example.androidseekbar; 2 3 import android.os.Bundle; 4 import android.app.Activity; 5 import android.view.Menu; 6 import android.widget.ImageView; 7 import android.widget.RatingBar; 8 import android.widget.RatingBar.OnRatingBarChangeListener; 9 import android.widget.SeekBar;10 import android.widget.SeekBar.OnSeekBarChangeListener;11 12 public class AndroidSeekBarActivity extends Activity {13 14 @Override15 protected void onCreate(Bundle savedInstanceState) {16 super.onCreate(savedInstanceState);17 setContentView(R.layout.activity_android_seek_bar);18 19 final ImageView img = (ImageView) this.findViewById(R.id.img);20 SeekBar sekbar = (SeekBar) this.findViewById(R.id.sekbar);21 sekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {22 23 @Override24 public void onStopTrackingTouch(SeekBar seekBar) {25 // TODO Auto-generated method stub26 27 }28 29 @Override30 public void onStartTrackingTouch(SeekBar seekBar) {31 // TODO Auto-generated method stub32 33 }34 35 @Override36 public void onProgressChanged(SeekBar seekBar, int progress,37 boolean fromUser) {38 // 拖动时触发39 img.setAlpha(progress);40 }41 });42 43 RatingBar ratbar=(RatingBar)this.findViewById(R.id.ratbar);44 ratbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {45 46 @Override47 public void onRatingChanged(RatingBar arg0, float rating, boolean arg2) {48 //动态改变图片透明度49 img.setAlpha((int)(rating*255/5));50 }51 });52 }53 54 @Override55 public boolean onCreateOptionsMenu(Menu menu) {56 // Inflate the menu; this adds items to the action bar if it is present.57 getMenuInflater().inflate(R.menu.activity_android_seek_bar, menu);58 return true;59 }60 61 }
本文转自欢醉博客园博客,原文链接http://www.cnblogs.com/zhangs1986/archive/2013/02/28/2937157.html如需转载请自行联系原作者
欢醉