欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2020年01月07日 08:38:29   作者:霸道流氓  
這篇文章主要介紹了Android中使用SeekBar拖動(dòng)條實(shí)現(xiàn)改變圖片透明度,需要的朋友可以參考下

場景

效果

實(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: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的進(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拖動(dòng)條實(shí)現(xiàn)改變圖片透明度(代碼實(shí)現(xiàn)),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

最新評論