layout.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ImageView android:layout_width="80dp" android:layout_height="80dp" android:scaleType="center" android:background="#f00" android:src="@drawable/close" android:id="@+id/tc1"/> <SeekBar android:layout_width="match_parent" android:layout_height="wrap_content" android:max="255" android:progress="255" android:id="@+id/kz1" /> </LinearLayout>
Layout.java
package com.hanqi.application3; import android.app.Activity; import android.os.Bundle; import android.widget.ImageView; import android.widget.SeekBar; /** * Created by Administrator on 2016/3/31. */ public class Layout extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout); final ImageView tc1 = (ImageView)findViewById(R.id.tc1); final SeekBar kz1 = (SeekBar)findViewById(R.id.kz1); kz1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tc1.setImageAlpha(progress);
//如果最大值是100
//tc1.setImageAlpha(progress*255/100);
} @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); } }