SeekBar拖动条的功能和用法
拖动条和进度条比较相似,拖动条通过滑块的位置标识数值
。拖动条允许用户拖动滑块改变数值
public class MainActivity extends Activity {
ImageView iv;
SeekBar seb;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.seekbar);
iv=(ImageView) findViewById(R.id.photo);
seb=(SeekBar) findViewById(R.id.seekbar);
seb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
//当滑块位置发生改变是触发该方法
@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
// TODO Auto-generated method stub
//设置图片透明度
iv.setImageAlpha(arg1);
}
});
}
}
android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > android:id="@+id/photo" android:layout_width="match_parent" android:layout_height="240dp" android:src="@drawable/mia10"/> android:id="@+id/seekbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="255" android:progress="255" android:thumb="@drawable/mia4"/>