修复剪裁窗口画布控件缩放和布局问题

- 修复ZoomContainerView缩放按钮无效问题,添加onLayout正确缩放子视图
- 修复CropCanvasView裁剪框显示不一致问题
- 更新libappbase版本到15.15.20
- 优化剪裁窗口布局
This commit is contained in:
2026-04-28 09:15:43 +08:00
parent 31ea5c8fbb
commit 1cca476acd
5 changed files with 75 additions and 27 deletions

View File

@@ -109,7 +109,7 @@ dependencies {
*/
// WinBoLL库 nexus.winboll.cc 地址
api 'cc.winboll.studio:libaes:15.15.9'
api 'cc.winboll.studio:libappbase:15.15.19'
api 'cc.winboll.studio:libappbase:15.15.20'
// WinBoLL备用库 jitpack.io 地址
//api 'com.github.ZhanGSKen:AES:aes-v15.15.7'

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Mon Apr 27 15:42:17 CST 2026
#Tue Apr 28 09:10:54 CST 2026
stageCount=7
libraryProject=
baseVersion=15.0
publishVersion=15.0.6
buildCount=16
buildCount=22
baseBetaVersion=15.0.7

View File

@@ -221,8 +221,30 @@ public class CropCanvasView extends View {
}
public void scaleToView(int viewWidth, int viewHeight) {
requestLayout();
invalidate();
if (viewWidth > 0 && viewHeight > 0 && canvasWidth > 0 && canvasHeight > 0) {
float scale = Math.max((float) viewWidth / canvasWidth, (float) viewHeight / canvasHeight);
int oldCanvasW = canvasWidth;
int oldCanvasH = canvasHeight;
canvasWidth = (int) (canvasWidth * scale);
canvasHeight = (int) (canvasHeight * scale);
float left = (canvasWidth - imageWidth) / 2f;
float top = (canvasHeight - imageHeight) / 2f;
imageBounds.set(left, top, left + imageWidth, top + imageHeight);
canvasBounds.set(0, 0, canvasWidth, canvasHeight);
if (cropRect != null) {
float scaleX = (float) canvasWidth / oldCanvasW;
float scaleY = (float) canvasHeight / oldCanvasH;
cropRect.left *= scaleX;
cropRect.top *= scaleY;
cropRect.right *= scaleX;
cropRect.bottom *= scaleY;
}
requestLayout();
invalidate();
}
}
public RectF getCropRect() {
@@ -295,15 +317,10 @@ public class CropCanvasView extends View {
canvas.restore();
canvas.drawRect(cropRect, borderPaint);
float scX = imageToScreenX(cropRect.left);
float scY = imageToScreenY(cropRect.top);
float scR = imageToScreenX(cropRect.right);
float scB = imageToScreenY(cropRect.bottom);
canvas.drawCircle(scX, scY, 12, cornerPaint);
canvas.drawCircle(scR, scY, 12, cornerPaint);
canvas.drawCircle(scX, scB, 12, cornerPaint);
canvas.drawCircle(scR, scB, 12, cornerPaint);
canvas.drawCircle(cropRect.left, cropRect.top, 12, cornerPaint);
canvas.drawCircle(cropRect.right, cropRect.top, 12, cornerPaint);
canvas.drawCircle(cropRect.left, cropRect.bottom, 12, cornerPaint);
canvas.drawCircle(cropRect.right, cropRect.bottom, 12, cornerPaint);
} else {
canvas.drawRect(cropRect, borderPaint);

View File

@@ -72,16 +72,27 @@ public class ZoomContainerView extends FrameLayout {
public void zoomIn() {
scaleFactor = Math.min(maxScale, scaleFactor + ZOOM_STEP);
invalidate();
requestLayout();
requestMeasure();
}
public void zoomOut() {
scaleFactor = Math.max(minScale, scaleFactor - ZOOM_STEP);
invalidate();
requestLayout();
requestMeasure();
}
private void requestMeasure() {
removeCallbacks(measureRunable);
post(measureRunable);
}
private Runnable measureRunable = new Runnable() {
@Override
public void run() {
requestLayout();
invalidate();
}
};
public float getScaleFactor() {
return scaleFactor;
}
@@ -94,17 +105,37 @@ public class ZoomContainerView extends FrameLayout {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int childCount = getChildCount();
if (childCount > 0) {
View child = getChildAt(0);
measureChild(child, widthMeasureSpec, heightMeasureSpec);
int childW = (int) (child.getMeasuredWidth() * scaleFactor);
int childH = (int) (child.getMeasuredHeight() * scaleFactor);
setMeasuredDimension(
MeasureSpec.getSize(widthMeasureSpec),
MeasureSpec.getSize(heightMeasureSpec)
);
child.measure(widthMeasureSpec, heightMeasureSpec);
int childW = child.getMeasuredWidth();
int childH = child.getMeasuredHeight();
int scaledW = (int) (childW * scaleFactor);
int scaledH = (int) (childH * scaleFactor);
int widthSpec = MeasureSpec.makeMeasureSpec(scaledW, MeasureSpec.EXACTLY);
int heightSpec = MeasureSpec.makeMeasureSpec(scaledH, MeasureSpec.EXACTLY);
child.measure(widthSpec, heightSpec);
setMeasuredDimension(scaledW, scaledH);
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
int childCount = getChildCount();
if (childCount > 0) {
View child = getChildAt(0);
int childW = child.getMeasuredWidth();
int childH = child.getMeasuredHeight();
int scaledW = (int) (childW * scaleFactor);
int scaledH = (int) (childH * scaleFactor);
int parentW = right - left;
int parentH = bottom - top;
int childLeft = (parentW - scaledW) / 2;
int childTop = (parentH - scaledH) / 2;
child.layout(childLeft, childTop, childLeft + scaledW, childTop + scaledH);
}
}

View File

@@ -71,7 +71,7 @@
<cc.winboll.studio.gallery.ZoomContainerView
android:id="@+id/zoom_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center">
<cc.winboll.studio.gallery.CropCanvasView