码迷,mamicode.com
首页 > 其他好文 > 详细

通过进度条控制图片的透明度

时间:2016-05-10 20:44:50      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:

Layout文件代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.hanqi.testapp2.TestActivity5"
    android:orientation="vertical">

    <SeekBar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/seekBar"
        android:max="250"
        android:progress="0"/>
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/niu"
        android:id="@+id/iv_1"/>
</LinearLayout>

Activity代码:

package com.hanqi.testapp2;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.SeekBar;

public class TestActivity4 extends AppCompatActivity {

    SeekBar seekBar;
    ImageView iv_1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test5);
        seekBar =(SeekBar)findViewById(R.id.seekBar);
        iv_1 =(ImageView)findViewById(R.id.iv_1);
        iv_1.setAlpha(0);
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) 

{

                iv_1.setAlpha(progress);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
    }
}

 

通过进度条控制图片的透明度

标签:

原文地址:http://www.cnblogs.com/beens/p/5479149.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!