2016-10-06 7 views

答えて

1

は、ボタンのクリック 保護され、ボイドのonCreate(バンドルsavedInstanceState){ super.onCreate(savedInstanceState)にするためにTouchImageViewクラス

public void zoomIn() { //bind on zoomIn Button 
    oldScale = saveScale; 

    if(saveScale<=maxScale) 
    { 
     saveScale += .5; 
     matrix.setScale(saveScale, saveScale); 
     setImageMatrix(matrix); 
     invalidate(); 

     // Center the image 
     // Center the image 
     if(bmHeight>bmWidth) 
     { 
     redundantXSpace = width - (saveScale * bmWidth); 
     redundantXSpace /= 2; 
     } 
     else 
     { 
      redundantYSpace = height - (saveScale * bmHeight) ; 
      redundantYSpace /= 2; 
     } 

     matrix.postTranslate(redundantXSpace , redundantYSpace); 
     setImageMatrix(matrix); 
     invalidate(); 
    } 
} 

public void zoomOut() { 


//Bind on zoom Out Button 

    if(saveScale>=minScale) 
    { 
     saveScale -= .5; 
     matrix.setScale(saveScale, saveScale); 
     setImageMatrix(matrix); 
     invalidate(); 

     // Center the image 
     if(bmHeight>bmWidth) 
     { 
     redundantXSpace = width - (saveScale * bmWidth); 
     redundantXSpace /= 2; 
     } 
     else 
     { 
      redundantYSpace = height - (saveScale * bmHeight) ; 
      redundantYSpace /= 2; 
     } 
     matrix.postTranslate(redundantXSpace , redundantYSpace); 
     setImageMatrix(matrix); 
     invalidate(); 
    } 
} 

にこれらの2メソッドを追加します。

setContentView(R.layout.LAYOUT_NAME); 

Button zoonIn = (Button)findViewById(R.id.ZOOM_IN_BUTTON_ID); 
Button zoonOut = (Button)findViewById(R.id.ZOOM_OUT_BUTTON_ID); 

final TouchImageView touch = (TouchImageView)findViewById(R.id.YOUR_TOUCH_IMAGE_VIEW_)ID); 

Bitmap bImage = BitmapFactory.decodeResource(this.getResources(), R.drawable.DRAWABLE_ID); 

touch.setImageBitmap(bImage); 

touch.setMaxZoom(4f); //change the max level of zoom, default is 3f 


zoonIn.setOnClickListener(new OnClickListener() { 

    @Override 
    public void onClick(View v) { 
     // TODO Auto-generated method stub 
     touch.zoomIn(); 
    } 
}); 


zoonOut.setOnClickListener(new OnClickListener() { 

    @Override 
    public void onClick(View v) { 
     // TODO Auto-generated method stub 
     touch.zoomOut(); 
    } 
}); 

} 
+0

優秀な回答!あなたは私の一日を救った。ありがとうございました。 – Sermilion

+0

私の喜び.. .. @ scat95 –

0
**dependencies { 
    compile 'com.github.chrisbanes:PhotoView:1.3.0'//image zooming 
}** 

インポートあなたのgradel詳細については

にこの:あなたが好きなXMLでアニメーションを作成することができますhttps://github.com/chrisbanes/PhotoView

1

/RES /アニメーション/ zoominを。 xml:

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillEnabled="true" 
    android:fillAfter="true"> 
    <scale 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:duration="2000" 
     android:fromXScale="1" 
     android:fromYScale="1" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:toXScale="1.5" 
     android:fillEnabled="true" 
     android:fillAfter="true" 
     android:toYScale="1.5" > 
    </scale> 
</set> 

と別のような:

/res/anim/zoomout.xml:あなたのonCreateで

<?xml version="1.0" encoding="utf-8"?> 
<set 
    android:fillEnabled="true" 
    android:fillAfter="true" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <scale 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:duration="2000" 
     android:fromXScale="1.5" 
     android:fromYScale="1.5" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:fillEnabled="true" 
     android:fillAfter="true" 
     android:toXScale="1" 
     android:toYScale="1" > 
    </scale> 
</set> 

Animation zoomin= AnimationUtils.loadAnimation(this, R.anim.zoomin); 
Animation zoomout= AnimationUtils.loadAnimation(this, R.anim.zoomout); 

そして、あなたのボタンonClickListenerに呼び出す:

myImageView.startAnimation(zoomin); 

願っています。