中秋節學習,,android
經過拖動滑塊,改變圖片的透明度ide
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/image" android:layout_width="match_parent" android:layout_height="240dp" android:src="@drawable/lijiang"/> <!-- 定義一個拖動條,並改變它的滑塊外觀 --> <SeekBar android:id="@+id/seekbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="255" android:progress="255" android:thumb="@mipmap/ic_launcher"/> </LinearLayout>
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val image = findViewById<ImageView>(R.id.image) val seekBar = findViewById<SeekBar>(R.id.seekbar) seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { // 當拖動條的滑塊位置發生改變時觸發該方法 override fun onProgressChanged(bar: SeekBar, progress: Int, fromUser: Boolean) { // 動態改變圖片的透明度 image.imageAlpha = progress } override fun onStartTrackingTouch(bar: SeekBar) { } override fun onStopTrackingTouch(bar: SeekBar) { } }) }