Android studio 015 改变图片透明度SeekBar
生活随笔
收集整理的這篇文章主要介紹了
Android studio 015 改变图片透明度SeekBar
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
第一步
添加圖片到mipmap
第二步
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".MainActivity"><ImageViewandroid:id="@+id/image"android:layout_width="match_parent"android:layout_height="250dp"android:src="@mipmap/bbb"></ImageView><SeekBarandroid:id="@+id/seekbar"android:layout_width="match_parent"android:layout_height="wrap_content"android:max="255"android:progress="255" /></LinearLayout>
第三步
package com.example.mytouming;import androidx.appcompat.app.AppCompatActivity;import android.hardware.SensorEventListener;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.SeekBar;public class MainActivity extends AppCompatActivity {private SeekBar seekBar;private ImageView image;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);image = findViewById(R.id.image);seekBar = findViewById(R.id.seekbar);seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {@Overridepublic void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {image.setImageAlpha(progress);}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {}@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {}});}
}
總結
以上是生活随笔為你收集整理的Android studio 015 改变图片透明度SeekBar的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 年轻人,买什么也别买房
- 下一篇: labelme: 用于将黑红色mask标