xml文件中,定义一个ImageView和一个SeekBar:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#C0C0CC"
android:orientation="vertical"
android:padding="5dp">
<ImageView
android:id="@+id/imageView_seekBar"
android:layout_width="match_parent"
android:layout_height="200dp"
android:src="@mipmap/img5" />
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="255"
android:progress="255" />
</LinearLayout>
在MainActivity中写入逻辑:
final ImageView image = (ImageView) findViewById(R.id.imageView_seekBar);
SeekBar seekbar = (SeekBar) findViewById(R.id.seekBar);
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onProgressChanged(SeekBar arg, int i, boolean b) {
//动态改变图片的透明度
image.setImageAlpha(i);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
更多好内容戳下面:
https://blog.csdn.net/wuqingsen1