Android program to zoom in and out using the search button?

I want to enlarge and reduce the image in relation to the movement of the search bar !! can someone help me do this please your quick reply would be much appreciated !!

+4
source share
2 answers

The onProgressChanged () method does the magic I want !!

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; } 

}

+4
source

I do not quite understand if this is what you want, but here are some links that may help you.

This should understand how seekbars work. You need to install a listener. http://rajeshvijayakumar.blogspot.pt/2013/01/seek-bar-example-in-android.html

After that, you need to get the seekbar values ​​and use this exame to scale the bitmap using BitmapFactory . http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

Hope this helps.

+1
source

Source: https://habr.com/ru/post/1486211/


All Articles