新聞中心
本篇文章給大家分享的是有關Android中怎么利用SeekBar拖動條改變圖片透明度,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
成都創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務,包含不限于網(wǎng)站設計、成都做網(wǎng)站、龍圩網(wǎng)絡推廣、微信小程序開發(fā)、龍圩網(wǎng)絡營銷、龍圩企業(yè)策劃、龍圩品牌公關、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們最大的嘉獎;成都創(chuàng)新互聯(lián)公司為所有大學生創(chuàng)業(yè)者提供龍圩建站搭建服務,24小時服務熱線:13518219792,官方網(wǎng)址:www.cdcxhl.com
實現(xiàn)
將布局改為LinearLayout,并通過android:orientation="vertical">
設置為垂直布局,然后添加一個ImageView和SeekBar,并分別添加id屬性。
其中SeekBar,添加最大值為255.因為透明度的最大值就是255
android:max="255"
并設置當前值就是255
android:progress="255"
完整xml代碼
然后來到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拖動條改變圖片透明度,小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降?。希望你能通過這篇文章學到更多知識。更多詳情敬請關注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
當前名稱:Android中怎么利用SeekBar拖動條改變圖片透明度
分享地址:http://www.dlmjj.cn/article/iiosdg.html