2011-10-24 17 views
3

ギャラリーで選択した画像をどのように拡大縮小できますか?これを試しましたが、うまく機能しません。 `ギャラリーで選択した画像の拡大/縮小

public void onItemSelected (AdapterView<?> parent, View v, int position, long id) 
{ 
    Animation grow = AnimationUtils.loadAnimation(DetailTvShow.this, R.anim.grow); 

      Button btn = (Button)findViewById(R.id.button1); 
      btn.setText("saison "+(position+1)); 
      View sideView = v.findViewById(position + 1); 
      View sideView1 = v.findViewById(position - 1); 

      if ((sideView != null)||(sideView1 != null)){ 
       ((ImageView)sideView).setLayoutParams(new Gallery.LayoutParams(80, 115)); 

       ((ImageView)sideView1).setLayoutParams(new `enter code here`Gallery.LayoutParams(80, 115)); 

      } 

     /*  sideView = parent.findViewById(position + 1); 
      if (sideView != null) 
       ((ImageView)sideView).setLayoutParams(new Gallery.LayoutParams(80, 115)); */ 

      v.startAnimation(grow); 
      v.setLayoutParams(new Gallery.LayoutParams(105, 140)); 
     }` 
+0

およびres/anim/grow.xmlの場合 – Vervatovskis

+0

try setScaleType(ScaleType.FITXY); – Houcine

答えて

5

私は同じ問題を持っていた、私はここに提示するのと同様の解決策がありましたスタックのオーバーフローが発生しましたが、正常に動作しませんでしたが、ビューの縮尺は変わりますが、最終的には元のサイズに戻りません。

ここまで修正された修正がありましたが、これまでのところうまく動作しているようで、問題は発生していません。 RES /アニメーションで

何でも

<?xml version="1.0" encoding="utf-8"?> 
<scale xmlns:android="http://schemas.android.com/apk/res/android" 
     android:fromXScale="1.0" 
     android:toXScale="1.075" 
     android:fromYScale="1.0" 
     android:toYScale="1.075" 
     android:duration="150" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:interpolator="@android:anim/accelerate_decelerate_interpolator" 
     android:fillAfter="true"> 
</scale> 

コピーのために働く、このクラスにサイズを拡大し、あなたの活動にあなたの継承されたギャラリーまたは右に

それを置くためにgrow.xmlファイル 変更を作成しますあなたがあなたのギャラリークラスを作成し、アダプターのコールを接続した後、次に
private class SelectListener implements AdapterView.OnItemSelectedListener { 

     private Animation grow  = null; 
     private View  lastView = null; 

     public SelectListener(Context c) { 
      grow = AnimationUtils.loadAnimation(c, R.anim.grow); 
     } 

     public void onItemSelected(AdapterView<?> parent, View v, int position, long id)   { 

      // Shrink the view that was zoomed 
      try { if (null != lastView) lastView.clearAnimation(); 
      } catch (Exception clear) { } 

      // Zoom the new selected view 
      try { v.startAnimation(grow); } catch (Exception animate) {} 

      // Set the last view so we can clear the animation 
      lastView = v; 
     } 

     public void onNothingSelected(AdapterView<?> parent) { 
     } 

    } 

yourGalleryName.setOnItemSelectedListener(new SelectListener(this)); 

これは私のために働いた、それはあなたのためにも私に知らせてください。

+0

それは動作します!ありがとうございました – Vervatovskis

+0

問題はありません。 – Idistic

+0

私のために働いていません –

1

多分これはあなたが正しい軌道に乗るのに役立ちます:

public class bitmaptest extends Activity { 
@Override 
public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    LinearLayout linLayout = new LinearLayout(this); 

    // load the origial BitMap (500 x 500 px) 
    Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), 
      R.drawable.android); 

    int width = bitmapOrg.width(); 
    int height = bitmapOrg.height(); 
    int newWidth = 200; 
    int newHeight = 200; 

    // calculate the scale - in this case = 0.4f 
    float scaleWidth = ((float) newWidth)/width; 
    float scaleHeight = ((float) newHeight)/height; 

    // createa matrix for the manipulation 
    Matrix matrix = new Matrix(); 
    // resize the bit map 
    matrix.postScale(scaleWidth, scaleHeight); 
    // rotate the Bitmap 
    matrix.postRotate(45); 

    // recreate the new Bitmap 
    Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, 
         width, height, matrix, true); 

    // make a Drawable from Bitmap to allow to set the BitMap 
    // to the ImageView, ImageButton or what ever 
    BitmapDrawable bmd = new BitmapDrawable(resizedBitmap); 

    ImageView imageView = new ImageView(this); 

    // set the Drawable on the ImageView 
    imageView.setImageDrawable(bmd); 

    // center the Image 
    imageView.setScaleType(ScaleType.CENTER); 

    // add ImageView to the Layout 
    linLayout.addView(imageView, 
      new LinearLayout.LayoutParams(
        LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT 
      ) 
    ); 

    // set LinearLayout as ContentView 
    setContentView(linLayout); 
} 

}

関連する問題