
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"/>原文地址:http://blog.csdn.net/u012637501/article/details/46239493