麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > OS > 安卓 > 正文

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

2024-09-11 17:15:21
字體:
來源:轉載
供稿:網友

場景

效果

實現

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

其中SeekBar,添加最大值為255.因為透明度的最大值就是255

 android:max="255"

并設置當前值就是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的進度條改變事件中給imageView設置透明度。

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) {      }    });  }}

總結

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 日本a∨精品中文字幕在线 欧美1—12sexvideos | 欧美 日韩 国产 成人 | 桥本有菜免费av一区二区三区 | 中文字幕精品在线视频 | 特大黑人videos与另类娇小 | 欧美激情 在线播放 | 97zyz成人免费视频 | 97zyz成人免费视频 | 国产亚洲精品影达达兔 | 国产亚洲精品视频中文字幕 | 全黄性色大片 | 圆产精品久久久久久久久久久 | 国产精品av久久久久久久久久 | 中国a毛片 | 一本免费视频 | 91丝袜| 毛片免费在线视频 | 亚洲一区二区三区视频 | 免费国产在线精品 | 午夜在线视频观看 | 美女性感毛片 | 国产91久久久久 | 久久久一区二区 | 九九热在线视频观看这里只有精品 | 黄色片免费视频 | 国产羞羞视频在线观看免费应用 | 国产精品久久久久久久久粉嫩 | 91av国产在线 | 美女视频免费一区二区 | 久久精品视频首页 | 亚洲精品一区二区三区大胸 | 国产一区二区三区撒尿在线 | 电影一级毛片 | 亚洲91精品 | 欧美成人精品不卡视频在线观看 | 亚洲尻逼视频 | 羞羞的动漫在线观看 | 欧美精品一区二区三区在线 | www.99re14.com | 日本成人一区二区 | 狠狠干五月天 |