我正在尝试将捏合/缩放功能添加到着名的位图项目(如Gallery应用程序)。 我想我必须在ImageDetailActivity.java文件中实现它,但我不知道该怎么做..
是否有人可以让我走上正确的道路?
或许有人可以为Gallery应用程序(我们可以在所有androïd手机中找到相同的应用程序)获得教程(或来源?)。
谢谢!
答案 0 :(得分:1)
没有理由重新发明轮子。以下是一些允许在ImageView上进行缩放和缩放的库:
https://github.com/jasonpolites/gesture-imageview
https://github.com/chrisbanes/PhotoView
https://github.com/MikeOrtiz/TouchImageView
它们使用起来非常简单,而且大多数都包含示例代码。
答案 1 :(得分:0)
我在工作区中有一个例子。看看你是否想要它。
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener;
import android.widget.TextView;
import android.widget.Toast;
public class PinchExampleActivity extends Activity {
TextView scaleText;
ScaleGestureDetector scaleGestureDetector;
private int number;
private String teste;
private int result;
private int myNum;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pinch_example);
scaleText = (TextView)findViewById(R.id.myTextView);
//teste = scaleText.getText().toString();
myNum = 0;
try {
myNum = Integer.parseInt(scaleText.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
//number = Integer.parseInt(teste);
Toast.makeText(PinchExampleActivity.this, "fdsdfsfdsf " + myNum, Toast.LENGTH_SHORT).show();
scaleGestureDetector =
new ScaleGestureDetector(this,
new MyOnScaleGestureListener());
}
@Override
public boolean onTouchEvent(MotionEvent event) {
scaleGestureDetector.onTouchEvent(event);
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.pinch_example,
menu);
return true;
}
public class MyOnScaleGestureListener extends
SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
float scaleFactor = detector.getScaleFactor();
if (scaleFactor > 1) {
myNum++;
String teste = Integer.toString(myNum);
scaleText.setText(teste);
} else {
myNum--;
String teste1 = Integer.toString(myNum);
scaleText.setText(teste1);
}
return true;
}
@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
return true;
}
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
}
}
}