두 개의 버튼 (하나는 확대, 다른 하나는 축소)으로 ImageView를 확대/축소 할 수 있어야합니다. MotionEvent를 사용하여 확대/축소를 성공적으로 구현했지만 버튼을 구현하는 방법을 모릅니다. 가짜 MotionEvents 또는 유사한 것을 만들 수 있습니까?Android : 버튼이있는 ImageView (MotionEvent가없는 이미지)
1
A
답변
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();
}
}
에서이 두 방법을 추가;
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
**dependencies {
compile 'com.github.chrisbanes:PhotoView:1.3.0'//image zooming
}**
수입하여 gradel 자세한 내용은
이 : 당신은 같은 XML에서 애니메이션을 만들 수 있습니다 https://github.com/chrisbanes/PhotoView
1
:
/고해상도/ANIM/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>
:
myImageView.startAnimation(zoomin);
:
Animation zoomin= AnimationUtils.loadAnimation(this, R.anim.zoomin);
Animation zoomout= AnimationUtils.loadAnimation(this, R.anim.zoomout);
그리고 당신의 버튼 OnClickListener를 요청한다
도움이 되길 바랍니다.
우수 답변! 너는 내 하루를 구했다. 고맙습니다. – Sermilion
내 기쁨 .. :) @ scat95 –