Tôi đang gặp vấn đề lạ. Tôi chia tỷ lệ hình ảnh và, trong khi chia tỷ lệ hoạt động chính xác, hình ảnh luôn bị cắt bớt. Tôi đã thử các loại quy mô khác nhau - mọi thứ đã thay đổi nhưng tôi không bao giờ có thể làm cho nó hoạt động.Tại sao hình ảnh của tôi bị cắt bớt sau khi chia tỷ lệ?
Chỉ cần được rõ ràng, đây là những gì tôi cần phải giải quyết: 1. Tôi có một HorizontalScrollView
quanh ImageView
và ScrollView
quanh HorizontalView
. 2. Tôi cuộn xung quanh (sử dụng scrollTo
của cả hai chế độ xem cuộn) và, khi có một sự kiện nhất định, hãy phóng to. 3. Điều tôi muốn xảy ra là dành cho ImageView
để xoay quanh vị trí cuộn hiện tại của tôi.
Dưới đây là cách bố trí:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:overScrollMode="never">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:overScrollMode="never">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:scaleType="fitCenter" />
</HorizontalScrollView>
</ScrollView>
</FrameLayout>
Và đây là đoạn code rộng (originalWidth
/originalHeight
được tính theo quy mô của 1
; targetView
điểm đến ImageView
):
public synchronized void changeScale(float newScaleFactor) {
this.scaleFactor = Math.max(min_zoom, Math.min(newScaleFactor, max_zoom));
if (targetView != null && originalWidth > 0) {
int newWidth = (int)(originalWidth * scaleFactor);
int newHeight = (int)(originalHeight * scaleFactor);
onScaleChanged(targetView, scaleFactor, newWidth, newHeight);
}
}
public void onScaleChanged(View targetView, float scaleFactor, int newWidth, int newHeight) {
ViewGroup.LayoutParams layoutParams = targetView.getLayoutParams();
layoutParams.width = newWidth;
layoutParams.height = newHeight;
// This is needed to increase the pane size (rather than zoom within the initial layout)
targetView.setLayoutParams(layoutParams);
// Tell the system to recalculate the layout
targetView.requestLayout();
// This is needed to specify the center of scaling
HorizontalScrollView horizontalScrollView = (HorizontalScrollView)targetView.getParent();
ScrollView vertScrollView = (ScrollView)horizontalScrollView.getParent();
// ~~~ the pivot points are probably wrong
targetView.setPivotX(horizontalScrollView.getScrollX() * scaleFactor);
targetView.setPivotY(vertScrollView.getScrollY() * scaleFactor);
// This is needed for actual zooming
targetView.setScaleX(scaleFactor);
targetView.setScaleY(scaleFactor);
};
public void zoomIn(float scaleDelta) {
changeScale(scaleFactor + scaleDelta);
}
public void zoomOut(float scaleDelta) {
changeScale(scaleFactor - scaleDelta);
}
Câu hỏi 1: Làm thế nào Tôi ngăn chặn cắt? Tôi không thể tìm thấy sự kết hợp phù hợp của scaleType
và thay đổi kích thước bố cục.
Câu hỏi 2: Khi tôi sử dụng setScaleX
/setScaleY
, trục của tôi có được tính sau khi áp dụng hệ số tỷ lệ mới hay trình kết xuất tự động xử lý điều đó không?
dường như với tôi như bạn nên xác minh rằng các giá trị bạn đang đặt cho kích thước hình ảnh của bạn nằm trong giới hạn của màn hình. Tôi tưởng tượng rằng một trong những được thiết lập đúng nhưng một trong những khác tràn. –
Hình ảnh của tôi nằm trong ScrollView. Nó có thể là bất kỳ kích thước nào tôi muốn.Các clipping tôi phàn nàn về là giới hạn scrollview nơi tôi di chuyển – Yevgeniy
Để tiếp tục xây dựng, vấn đề của tôi là gần như giống hệt nhau để http://stackoverflow.com/questions/4963866/how-to-change-size-of-android-scrollview. Sự khác biệt duy nhất là tôi mở rộng con của ScrollView trong khi người đó thay đổi hoàn toàn đứa trẻ. – Yevgeniy