Android 通过seekBar设置图片透明度

本文介绍如何在Android应用中通过SeekBar组件实现图片透明度的动态调整,使用Java代码详细解析实现过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Java代码:

package com.example.android07_widget;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;

/**
 * Created by Administrator on 2017/7/19 0019.
 */

public class MainActivitythird extends AppCompatActivity {

    private ImageView iv_mainthird_image;
    private int  currentAlpta=255;
    private SeekBar sb_mainthird_seekBar;
    private int n=R.drawable.s10;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mainthird);
        iv_mainthird_image = (ImageView) findViewById(R.id.iv_mainthird_image);
        sb_mainthird_seekBar = (SeekBar) findViewById(R.id.sb_mainthird_seekBar);
        //设置默认清晰度
        iv_mainthird_image.setImageAlpha(currentAlpta);
        //设置一张默认默认图片
        iv_mainthird_image.setImageResource(n);
        //设置最大进度值
        sb_mainthird_seekBar.setMax(255);
        //进度条停止的最大值
        sb_mainthird_seekBar.setProgress(255);
        //通过SeekBar进度条,修改图片透明度
        sb_mainthird_seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                currentAlpta=i;
                iv_mainthird_image.setImageAlpha(currentAlpta);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });


    }

}

xml代码: 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <SeekBar
        android:id="@+id/sb_mainthird_seekBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

  <ImageView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/iv_mainthird_image"
      />

   
</LinearLayout>








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值