PercentageCropImageView
A custom AppCompatImageView that allows precise control over the visible crop area of an image by adjusting its horizontal and vertical center offset percentages.
Key Features:
Allows manual vertical or horizontal cropping via percentage offsets.
Works seamlessly with Coil, Glide, or any image loading library.
Usage (XML):
You can set the crop offset directly in XML using custom attributes:
<com.lagradost.cloudstream3.utils.PercentageCropImageView
android:id="@+id/home_scroll_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="matrix"
app:cropYCenterOffsetPct="0.2"
app:cropXCenterOffsetPct="0.5"
tools:src="@drawable/example_poster" />app:cropYCenterOffsetPct→ controls how far vertically the image shifts0.0= top-aligned,0.5= centered,1.0= bottom-aligned.app:cropXCenterOffsetPct→ controls how far horizontally the image shifts0.0= left,0.5= center,1.0= right.
Programmatic Example:
imageView.cropYCenterOffsetPct = 0.15f // Show slightly more (15%) of the top area
imageView.cropXCenterOffsetPct = 0.5f // Keep image centered horizontally
imageView.redraw() //Only needed if you changed cropYCenterOffsetPct/cropXCenterOffsetPct at runtimeNotes:
Must use
android:scaleType="matrix"to enable manual matrix transformations.Reference: https://stackoverflow.com/a/29055283
See also
Properties
the horizontal crop percentage (0.0–1.0)
the vertical crop percentage (0.0–1.0)
Functions
TYPE_SAFE_LOADERS