国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > OS > 安卓 > 正文

Android中使用SeekBar拖動條實(shí)現(xiàn)改變圖片透明度(代碼實(shí)現(xiàn))

2024-09-11 17:15:21
字體:
供稿:網(wǎng)友

場景

效果

實(shí)現(xiàn)

將布局改為LinearLayout,并通過android:orientation="vertical">設(shè)置為垂直布局,然后添加一個(gè)ImageView和SeekBar,并分別添加id屬性。

其中SeekBar,添加最大值為255.因?yàn)橥该鞫鹊淖畲笾稻褪?55

 android:max="255"

并設(shè)置當(dāng)前值就是255

android:progress="255"

完整xml代碼

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:andro  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"  tools:context=".SeekBarActivity"  android:orientation="vertical">  <ImageView    android:layout_width="match_parent"    android:    android:layout_height="250dp"    android:src="@drawable/dog"    />  <SeekBar    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:    android:max="255"    android:progress="255"    /></LinearLayout>

然后來到Activity

分別通過id獲取到ImageView和SeekBar

然后在seekBar的進(jìn)度條改變事件中給imageView設(shè)置透明度。

package com.badao.relativelayouttest;import androidx.annotation.RequiresApi;import androidx.appcompat.app.AppCompatActivity;import android.os.Build;import android.os.Bundle;import android.widget.ImageView;import android.widget.SeekBar;public class SeekBarActivity extends AppCompatActivity {  private SeekBar seekBar;  private ImageView imageView;  @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_seek_bar);    imageView = (ImageView) findViewById(R.id.image);    seekBar = (SeekBar) findViewById(R.id.seekBar);    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {      @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)      @Override      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {        imageView.setImageAlpha(progress);      }      @Override      public void onStartTrackingTouch(SeekBar seekBar) {      }      @Override      public void onStopTrackingTouch(SeekBar seekBar) {      }    });  }}

總結(jié)

以上所述是小編給大家介紹的Android中使用SeekBar拖動條實(shí)現(xiàn)改變圖片透明度(代碼實(shí)現(xiàn)),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對武林網(wǎng)之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 图木舒克市| 正宁县| 兴业县| 弥渡县| 宁都县| 磴口县| 句容市| 卢氏县| 德惠市| 宽城| 南岸区| 会东县| 涟水县| 蒙自县| 水富县| 平遥县| 石柱| 新巴尔虎右旗| 隆化县| 沧州市| 深圳市| 蓬莱市| 嘉善县| 安岳县| 汝州市| 拉孜县| 广河县| 上饶县| 池州市| 黄梅县| 东宁县| 乳山市| 涟源市| 越西县| 安庆市| 连云港市| 金坛市| 玛曲县| 建平县| 佛学| 铁岭市|