我正面临一个问题,我想在线性布局中实现捏缩放。
这是线性布局的Xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/backimage"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/load"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" />
</LinearLayout>
有问题地将一些数据添加到我的线性布局(@+id/load)
,但我想如何为我的线性布局添加缩放功能任何人都有这个想法。给我一些建议。
这里是onTouch()函数
case MotionEvent.ACTION_POINTER_UP:
if (zoom) {
// Log.d("detecting","inside the action pointer up");
float distY = detector.claculateDistanceY(event.getY(0), event.getY(1));
// for horizontal zoom
float finalX1 = Math.min(event.getX(0), event.getX(1));
pointNo1 = (int) (BitmapDetector.prevX1 / loadWaveFormManager.getPointDistance());
pointNo1 = loadWaveFormManager.getPreStart() + pointNo1;
float finalX2 = Math.max(event.getX(0), event.getX(1));
pointNo2 = (int) (BitmapDetector.prevX2 / loadWaveFormManager.getPointDistance());
pointNo2 = loadWaveFormManager.getPreStart()+ pointNo2;
// Log.d("detecting","zoom points calculated");
distX = detector.claculateDistanceX(finalX1, finalX2);
if (Math.abs(distX) <= Math.abs(distY)) {
// Log.d("detecting","distanceX is less than that of Y");
if ((loadWaveFormManager.getZoom() + distY) > 30) {
// Log.d("detecting","setting the paramenter for vertical zoom");
if (distY > 100) {
distY /= 3;
}
int tempZoom = (int) (loadWaveFormManager.getZoom() + distY);
loadWaveFormManager.setZoom(tempZoom);
}
} else {
if (distX > 0) {
zoomIn = true;
}
if (distX < 0) {
zoomIn = false;
}
distX += BitmapDetector.prevHoriZoom;
float maxZoomDist = ((float) StaticValues.screenWidth / (float) 100.0);
float minZoomDist = (float) StaticValues.screenWidth / (float) StaticValues.RecordLength;
float zoomDistRate = (float) (maxZoomDist - minZoomDist) / (float) StaticValues.RecordLength;
zoomDist = zoomDistRate * distX;
numberOfPointToDraw = 0;
if (zoomIn && BitmapDetector.prevHoriZoom < StaticValues.RecordLength) {
// Log.d("detecting","going to calculate the zoom in factors");
if (zoomDist >= maxZoomDist) {
// Log.d("detecting","case of max zoom");
zoomDist = maxZoomDist;
numberOfPointToDraw = (int) (StaticValues.screenWidth / zoomDist);
loadWaveFormManager.setStart(pointNo1);
loadWaveFormManager.setLimit(pointNo1 + 100);
loadWaveFormManager.setPreStart(loadWaveFormManager.getStart());
loadWaveFormManager.setPreLimit(loadWaveFormManager.getLimit());
loadWaveFormManager.setPointDistance(zoomDist);
BitmapDetector.prevHoriZoom = StaticValues.RecordLength;
} else {
// Log.d("detecting","not a case of max zoom");
numberOfPointToDraw = (int) (StaticValues.screenWidth / zoomDist);
// Log.d("zooming points","number fo points to draw:"+numberOfPointToDraw);
loadWaveFormManager.setPointDistance(zoomDist);
if (Math.abs(pointNo2 - pointNo1) < numberOfPointToDraw) {
// Log.d("detecting","zooming area does not have sifficent points");
while (Math.abs(pointNo1 - pointNo2) <= numberOfPointToDraw) {
if (pointNo1 > 0)
pointNo1--;
if (pointNo2 < StaticValues.RecordLength)
pointNo2++;
// Log.d("detecting","cycling for stuffing the points: pointno1:"+pointNo1+"pointno2"+pointNo2+"difference-"+Math.abs(pointNo1-pointNo2)+"numberOfPointToDraw:"+numberOfPointToDraw);
}
// Log.d("detecting","stuffing the point of zooming area");
loadWaveFormManager.setStart(pointNo1);
loadWaveFormManager.setLimit(pointNo2);
loadWaveFormManager.setPreStart(loadWaveFormManager.getStart());
loadWaveFormManager.setPreLimit(loadWaveFormManager.getLimit());
BitmapDetector.prevHoriZoom = distX;
// Log.d("zoom","inside Limit ZoomDist:"+zoomDist+" max Zoom Dist:"+maxZoomDist+" Start point:"+pointNo1+" End point:"+pointNo2);
} else if (Math.abs(pointNo2 - pointNo1) > numberOfPointToDraw) {
// Log.d("detecting","Zoom area have move then point required");
loadWaveFormManager.setStart(pointNo1);
pointNo2 = pointNo1+ numberOfPointToDraw;
loadWaveFormManager.setLimit(pointNo2);
loadWaveFormManager.setPreStart(loadWaveFormManager.getStart());
loadWaveFormManager.setPreLimit(loadWaveFormManager.getLimit());
BitmapDetector.prevHoriZoom = distX;
// Log.d("warning","inside Limit ZoomDist:"+zoomDist+" max Zoom Dist:"+maxZoomDist+" Start point:"+pointNo1+" End point:"+pointNo2);
} else {
// Log.d("detecting","zooming area have exactly same number of points");
loadWaveFormManager.setStart(pointNo1);
loadWaveFormManager.setLimit(pointNo2);
loadWaveFormManager.setPreStart(loadWaveFormManager.getStart());
loadWaveFormManager.setPreLimit(loadWaveFormManager.getLimit());
BitmapDetector.prevHoriZoom = distX;
}
}
} else if (zoomIn == false && BitmapDetector.prevHoriZoom > 0) {
if (zoomDist <= minZoomDist) {
zoomDist = minZoomDist;
numberOfPointToDraw = (int) ((float) StaticValues.screenWidth / (float) zoomDist);
pointNo1 = 0;
pointNo2 = StaticValues.RecordLength;
loadWaveFormManager.setStart(0);
loadWaveFormManager.setLimit(StaticValues.RecordLength);
loadWaveFormManager.setPreStart(loadWaveFormManager.getStart());
loadWaveFormManager.setPreLimit(loadWaveFormManager.getLimit());
loadWaveFormManager.setPointDistance(zoomDist);
BitmapDetector.prevHoriZoom = 0;
} else {
numberOfPointToDraw = (int) (StaticValues.screenWidth / zoomDist);
loadWaveFormManager.setPointDistance(zoomDist);
while (Math.abs(pointNo1 - pointNo2) <= numberOfPointToDraw) {
if (pointNo1 > 0)
pointNo1--;
if (pointNo2 < StaticValues.RecordLength)
pointNo2++;
}
loadWaveFormManager.setStart(pointNo1);
loadWaveFormManager.setLimit(pointNo2);
loadWaveFormManager.setPreStart(loadWaveFormManager.getStart());
loadWaveFormManager.setPreLimit(loadWaveFormManager.getLimit());
BitmapDetector.prevHoriZoom = distX;
}
} else {
}
}
}