如何在android中的库中缩放所选图像

时间:2011-05-20 08:55:33

标签: android

我的申请表中有一个图库。在那个画廊里我有很多图像。 任何人都可以告诉我如何放大android中图库中的选定图像?请显示示例代码。

我尝试使用此代码,但它无效:

 gallery.setOnItemClickListener(new OnItemClickListener() 
 {
     public void onItemClick(AdapterView parent, 
                    View v, int position, long id) 
     {

            if(v!=null)
                {
                if(position>0){
                View previousView=parent.findViewById(position-1);
                if(previousView!=null)
                {
                previousView.setLayoutParams(new Gallery.LayoutParams(100, 120)); 
                }
                }
                Toast.makeText(getBaseContext(), 
                        "pic" + (position + 1) + " selected", 
                        Toast.LENGTH_SHORT).show();
                Animation grow = AnimationUtils.loadAnimation(GalleryActivity.this, R.anim.grow);      
                    v.startAnimation(grow);      
                v.setLayoutParams(new Gallery.LayoutParams(170, 150)); 
                }

由于

1 个答案:

答案 0 :(得分:1)

此代码有效

 gl.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
      { public void onItemSelected(AdapterView<?> parent, View v, int
      position, long id) {

      if (lastview != null) lastview .setLayoutParams(new
      Gallery.LayoutParams(140, 280)); lastview = v; v.setLayoutParams(new
      Gallery.LayoutParams(170, 340)); }

      public void onNothingSelected(AdapterView<?> parent) { //
      System.out.println("NOTHING SELECTED");

      } });