Android-Image-Cropper
Android-Image-Cropper copied to clipboard
CropImageView fails to respect the match_parent size upon resizing the window
There are currently more and more users using large-screen Android devices, and these devices often allow users to resize the App window, which makes it necessary for us to display layouts correctly when the user resizes the window.
In my application, I have integrated the CropImageView
from your project and set its width and height attributes to match_parent
. However, upon resizing the window, the CropImageView
fails to respect the match_parent
setting, as illustrated in the attached screen recording:
https://github.com/CanHub/Android-Image-Cropper/assets/30869777/aea2b526-6aeb-4490-be95-13b9e1f40c88
To facilitate your understanding of the problem, I've prepared a simple, minimal reproducible project following these steps:
- Created an
Empty Views Activity
project. - Added the dependency
com.vanniktech:android-image-cropper:4.5.0
. - Set
MainActivity
toandroid:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|density|screenSize|smallestScreenSize"
inAndroidManifest.xml
to prevent the Android system from recreating the entire activity upon changes in the application's window size. - Placed a photo named
image.webp
in/res/raw/
. - Defined the contents of
activity_main.xml
andMainActivity.kt
as provided in the attached code snippet:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.canhub.cropper.CropImageView
android:id="@+id/crop_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:animateLayoutChanges="true"
app:cropAutoZoomEnabled="false"
app:cropShowProgressBar="false" />
</RelativeLayout>
package com.example.cropper
import android.graphics.BitmapFactory
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.canhub.cropper.CropImageView
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val cropImageView = findViewById<CropImageView>(R.id.crop_image_view)
val bitmap = resources.openRawResource(R.raw.image).use {
BitmapFactory.decodeStream(it)
}
cropImageView.setImageBitmap(bitmap)
}
}
You may download this project file to quickly verify the issue: CropperViewSizeIssue.zip
While the screen recording was captured in the Windows Subsystem for Android, I have validated that this issue persists across Desktop virtual devices (in Android Studio) and MIUI physical devices.
Ideally, when the width and height of the CropImageView
are set to match_parent
, its size should consistently adhere to that of the parent layout, maintaining parity with the behavior of other Views, such as the ImageView below:
https://github.com/CanHub/Android-Image-Cropper/assets/30869777/f07b201f-732c-4873-96b6-2661780b7dac
I would greatly appreciate any insights or assistance you can provide in resolving this matter. Please let me know if further clarification or additional information is needed from my end. Thank you for your attention to this issue, and I look forward to your response.
Good find. Probably no one ever thought of this feature. Feel free to submit a PR which fixes this.