드래그 확대 / 축소를 위해 앱에서 Matrix를 사용하고 있습니다. 사용자 지정 ImageView를 사용합니다.
내 문제:
드래그의 한계를 제어 할 수 없습니다 (최대 및 최소 확대가 완료되었습니다)
줌에 따라 매트릭스의 값을 찾아서 해결하려고하지만 장치에 따라 달라지기 때문에 더 좋은 방법은 아니며 0.9에서 1.7 사이에서 줌을 수동으로 제어 할 수 있습니다.
코너를 제어하는 더 나은 방법이 필요합니다.
내 문제는 행렬의 값 [2]과 값 [5]에 있습니다.
도움을 주셔서 감사합니다. 감사합니다! :디
이제 코드
이를 위해 지금 사용하는 두 가지 방법이 있습니다.
이 메서드는 행렬 (값 [0] 및 값 [4])의 확대 / 축소를 확인하고 사용자 지정 매개 변수를 limitCorners (float float)로 보냅니다.
public void checkZoom(){
float[] values = new float[9];
matrix.getValues(values);
//compruebo el zoom
float scaleX = values[Matrix.MSCALE_X];
float scaleY = values[Matrix.MSCALE_Y];
if(scaleX > MAX_ZOOM) {
scaleX = MAX_ZOOM;
} else if(scaleX < MIN_ZOOM) {
scaleX = MIN_ZOOM;
}
if(scaleY > MAX_ZOOM) {
scaleY = MAX_ZOOM;
} else if(scaleY < MIN_ZOOM) {
scaleY = MIN_ZOOM;
}
values[Matrix.MSCALE_X] = scaleX;
values[Matrix.MSCALE_Y] = scaleY;
matrix.setValues(values);
//Second part: depend zoom send values
//a limitaBordes(float, float)
valores = new float[9];
matrix.getValues(valores);
if (valores[0]<=MIN_ZOOM){
valores[0]=MIN_ZOOM;
valores[4]=MIN_ZOOM;
valores[2]=0;
valores[5]=0;
matrix.setValues(valores);
//imageView.setImageMatrix(matrix);
}else if(valores[0]>0.9 && valores[0]<=1){
limitCorners(-65, -40);
}else if(valores[0]>1 && valores[0]<=1.1){
limitCorners(-166, -123);
}else if(valores[0]>1.1 && valores[0]<=1.2){
limitCorners(-246, -201);
}else if(valores[0]>1.2 && valores[0]<=1.3){
limitCorners(-316, -280);
}else if(valores[0]>1.3 && valores[0]<=1.4){
limitCorners(-409, -359);
}else if(valores[0]>1.4 && valores[0]<=1.5){
limitCorners(-484, -435);
}else if(valores[0]>1.5 && valores[0]<=1.6){
limitCorners(-563, -521);
}else {// (valores[0]>1.6f)
limitCorners(-664, -600);
}
}
>
void limitCorners(float valorX, float valorY){
//log("determinando");
//if(x>0)
if(valores[2]>0){
valores[2]=0;
matrix.setValues(valores);
}//if(y>0)
if(valores[5]>0){
valores[5]=0;
matrix.setValues(valores);
}//if(x<valorX)
if(valores[2]< valorX){
valores[2]= valorX;
matrix.setValues(valores);
}//if(y<valorY)
if(valores[5]< valorY){
valores[5]= valorY;
matrix.setValues(valores);
}
imageView.setImageMatrix(matrix);
}
나는 그것을 해결한다!
누군가 같은 문제가 있으면 여기에 코드를 넣었습니다.
public void checkZoom(){
float[] values = new float[9];
matrix.getValues(values);
float scaleX = values[Matrix.MSCALE_X];
if(scaleX > MAX_ZOOM) {
setZoom(MAX_ZOOM);
}
else if(scaleX < MIN_ZOOM) {
setZoom(MIN_ZOOM);
}
limitCorners();
}
private void limitCorners() {
viewWidth = this.getWidth();
viewHeight = this.getHeight();
float []m = new float[9];
matrix.getValues(m);
float transX = m[Matrix.MTRANS_X];
float transY = m[Matrix.MTRANS_Y];
float fixTransX = getFixTrans(transX, viewWidth, getImageWidth());
float fixTransY = getFixTrans(transY, viewHeight, getImageHeight());
if (fixTransX != 0 || fixTransY != 0) {
matrix.postTranslate(fixTransX, fixTransY);
}
matrix.getValues(m);
if (getImageWidth() < viewWidth) {
m[Matrix.MTRANS_X] = (viewWidth - getImageWidth()) / 2;
}
if (getImageHeight() < viewHeight) {
m[Matrix.MTRANS_Y] = (viewHeight - getImageHeight()) / 2;
}
matrix.setValues(m);
}
private float getFixTrans(float trans, float viewSize, float contentSize) {
float minTrans, maxTrans;
if (contentSize <= viewSize) {
minTrans = 0;
maxTrans = viewSize - contentSize;
} else {
minTrans = viewSize - contentSize;
maxTrans = 0;
}
if (trans < minTrans)
return -trans + minTrans;
if (trans > maxTrans)
return -trans + maxTrans;
return 0;
}
/** Get the width of image (bitmapWidth*Zoom)*/
float getImageWidth(){
float []m = new float[9];
matrix.getValues(m);
return m[Matrix.MSCALE_X]*bitmap.getWidth();
}
/** Get the Height of image (bitmapHeight*Zoom)*/
float getImageHeight(){
float []m = new float[9];
matrix.getValues(m);
return m[Matrix.MSCALE_X]*bitmap.getHeight();
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다