本文介绍了为放大和缩小与搜索栏的帮助Android程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要放大和缩小图像相对于搜索栏的运动! !谁能帮我做这件事请你的回应会是非常AP preciated! ! !

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 ! ! !

推荐答案

onProgressChanged()方法做的,我想神奇! !

onProgressChanged() method do the magic which i want to ! !

公共类MainActivity扩展活动实现OnSeekBarChangeListener{

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

}

这篇关于为放大和缩小与搜索栏的帮助Android程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-13 01:36