Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CropImageView fails to respect the match_parent size upon resizing the window #610

Open
tasy5kg opened this issue Jan 28, 2024 · 1 comment

Comments

@tasy5kg
Copy link

tasy5kg commented Jan 28, 2024

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:

2024-01-28.215508_o.mp4

To facilitate your understanding of the problem, I've prepared a simple, minimal reproducible project following these steps:

  1. Created an Empty Views Activity project.
  2. Added the dependency com.vanniktech:android-image-cropper:4.5.0.
  3. Set MainActivity to android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|density|screenSize|smallestScreenSize" in AndroidManifest.xml to prevent the Android system from recreating the entire activity upon changes in the application's window size.
  4. Placed a photo named image.webp in /res/raw/.
  5. Defined the contents of activity_main.xml and MainActivity.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:

2024-01-28.224837_o.mp4

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.

@vanniktech
Copy link
Contributor

Good find. Probably no one ever thought of this feature. Feel free to submit a PR which fixes this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants