Extra features for your ImageView provided in a modularized way
An ImageView that supports different kind of cropping rather than the only Android is currently supporting: centerCrop
Using this library, you can crop your desired image by sides described below:
Development idea borns at the point in [Kerad Games] we needed images cropped by somewhere no matter the image size.
The original images we had to deal with (we wanted the half size of the ball shown whatever screen size), below
Here are some screenshots what we got thanks to this widget :-)
dependencies {
compile 'com.cesards.android:cropimageview:1.0.2.1'
}
<dependency>
<groupId>com.cesards.android</groupId>
<artifactId>CropImageView</artifactId>
<version>1.0.2</version>
<type>aar</type>
</dependency>
Define in xml:
<com.codeforvictory.android.superimageview.SuperImageView
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="@+id/imageView1"
android:src="https://github.com/cesards/SuperImageView/raw/master/@drawable/photo1"
custom:crop="value" />
where value
can take values
topLeft|centerLeft|bottomLeft|topRight|centerRight|bottomRight|centerTop|centerBottom
Or in code:
final CropImageView cropImageView = new CropImageView(CropActivity.this);
final Resources res = getResources();
cropImageView.setImageDrawable(res.getDrawable(images[position]));
final CropImageView.CropType cropType = imageCrops[position];
cropImageView.setCropType(cropType);
V/TestForegroundImageView﹕ ⇢ setFrame(l=0, t=0, r=1080, b=1557)
V/TestForegroundImageView﹕ ⇠ setFrame [0ms] = true
V/TestForegroundImageView﹕ ⇢ setFrame(l=1080, t=0, r=2160, b=1557)
V/TestForegroundImageView﹕ ⇠ setFrame [0ms] = true
V/TestForegroundImageView﹕ ⇢ setFrame(l=0, t=0, r=1080, b=1557)
V/TestForegroundImageView﹕ ⇠ setFrame [0ms] = false
V/TestForegroundImageView﹕ ⇢ setFrame(l=1080, t=0, r=2160, b=1557)
V/TestForegroundImageView﹕ ⇠ setFrame [0ms] = false
V/TestForegroundImageView﹕ ⇢ setFrame(l=0, t=0, r=1080, b=1701)
V/TestForegroundImageView﹕ ⇠ setFrame [0ms] = true
V/TestForegroundImageView﹕ ⇢ setFrame(l=1080, t=0, r=2160, b=1701)
V/TestForegroundImageView﹕ ⇠ setFrame [0ms] = true`
V/TestForegroundCropImageView﹕ ⇢ setFrame(l=0, t=0, r=1080, b=1557)
V/TestForegroundCropImageView﹕ ⇠ setFrame [0ms] = true
V/TestForegroundCropImageView﹕ ⇢ setFrame(l=1080, t=0, r=2160, b=1557)
V/TestForegroundCropImageView﹕ ⇠ setFrame [0ms] = true
V/TestForegroundCropImageView﹕ ⇢ setFrame(l=0, t=0, r=1080, b=1557)
V/TestForegroundCropImageView﹕ ⇠ setFrame [0ms] = false
V/TestForegroundCropImageView﹕ ⇢ setFrame(l=1080, t=0, r=2160, b=1557)
V/TestForegroundCropImageView﹕ ⇠ setFrame [0ms] = false
V/TestForegroundCropImageView﹕ ⇢ setFrame(l=0, t=0, r=1080, b=1701)
V/TestForegroundCropImageView﹕ ⇠ setFrame [0ms] = true
V/TestForegroundCropImageView﹕ ⇢ setFrame(l=1080, t=0, r=2160, b=1701)
V/TestForegroundCropImageView﹕ ⇠ setFrame [0ms] = true
Results: code used does not cause overhead in the UI thread.
@TargetApi
annotationminSdkVersion
to 7onLayout()
overhead. ImageView
onLayout()
is empty, so we only need logic in setFrame()
method.minSdkVersion="14"
).I'm pretty sure you there are some awesome hidden features you need in your daily dev life. Just let me know or collaborate to improve this librar
I'd like to improve this library with your help, there are some new features to implement waiting for you ;)
If you want to contribute, you should use my code styles available in the root of the project!