Android中怎么利用SeekBar拖動條改變圖片透明度

本篇文章給大家分享的是有關Android中怎么利用SeekBar拖動條改變圖片透明度,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

成都創(chuàng)新互聯公司專注為客戶提供全方位的互聯網綜合服務,包含不限于網站設計、成都做網站、龍圩網絡推廣、微信小程序開發(fā)、龍圩網絡營銷、龍圩企業(yè)策劃、龍圩品牌公關、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們最大的嘉獎;成都創(chuàng)新互聯公司為所有大學生創(chuàng)業(yè)者提供龍圩建站搭建服務,24小時服務熱線:13518219792,官方網址:muchs.cn

實現

將布局改為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: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"  tools:context=".SeekBarActivity"  android:orientation="vertical">  <ImageView    android:layout_width="match_parent"    android:id="@+id/image"    android:layout_height="250dp"    android:src="@drawable/dog"    />  <SeekBar    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:id="@+id/seekBar"    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拖動條改變圖片透明度,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注創(chuàng)新互聯行業(yè)資訊頻道。

本文名稱:Android中怎么利用SeekBar拖動條改變圖片透明度
分享網址:http://muchs.cn/article16/iiosdg.html

成都網站建設公司_創(chuàng)新互聯,為您提供企業(yè)網站制作商城網站、定制網站、域名注冊、定制開發(fā)服務器托管

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯

成都app開發(fā)公司