I want to zoom in and zoom out an image with respect to motion of the seek bar! ! can anyone help me to do this please your prompt response 'll be highly appreciated ! ! !
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
onProgressChanged() method do the magic which i want to ! !
public class MainActivity extends Activity implements OnSeekBarChangeListener {
private SeekBar mSeekBar;
Bitmap bm;
ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSeekBar = (SeekBar) findViewById(R.id.seekBar);
mSeekBar.setOnSeekBarChangeListener((OnSeekBarChangeListener) this);
image=(ImageView)findViewById(R.id.image);
bm=BitmapFactory.decodeResource(getResources(), R.drawable.sachin);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Bitmap resizedbitmap=Bitmap.createScaledBitmap(bm,10, 10, true);
if(progress>0&&progress<=25)
{
resizedbitmap=Bitmap.createScaledBitmap(bm,70, 70, true);
}
if(progress>26&&progress<=50)
{
resizedbitmap=Bitmap.createScaledBitmap(bm,120, 120, true);
}
if(progress>51&&progress<=75)
{
resizedbitmap=Bitmap.createScaledBitmap(bm,180, 180, true);
}
if(progress>76&&progress<=100)
{
resizedbitmap=Bitmap.createScaledBitmap(bm,220, 220, true);
}
image.setImageBitmap(resizedbitmap);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar)
{
mSeekBar.setSecondaryProgress(seekBar.getProgress());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
回答2:
I don't quite understand if this is what you want but here's some links that can help you with that.
This is to understand how seekbars
work. You need to set a listener.
http://rajeshvijayakumar.blogspot.pt/2013/01/seek-bar-example-in-android.html
After that, you need to get the values of the seekbar
and use this exame to scale the bitmap using BitmapFactory
.
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
Hope it helps.