Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🔥🔥🔥支持显示任意图形,只有你想不到没有它做不到;不直接操作Bitmap,可绘制圆形或圆角矩形背景边框,另外新增4种显示模式(Supports displaying arbitrary graphics, only you can't think of it, you can't do it without it; without directly operating Bitmap, you can draw a circular or rounded rectangle background frame, and add 4 new display modes)

License

NotificationsYou must be signed in to change notification settings

FlyJingFish/ShapeImageView

Repository files navigation

Maven centralGitHub starsGitHub forksGitHub issuesGitHub license

ShapeImageView supports circle or rounded corners, and can draw circle background borders or rounded box background borders. In addition to the built-in properties of ImageView, 4 new display modes are added;

AlmightyShapeImageView supports the display of arbitrary graphics, only you can't think of it, you can't do it without it;

The ImageView in this library does not directly operate Bitmap, but Drawable, as long as the system's ImageView supports it, it can be displayed (such as the gif image loaded by Glide), you can use it with confidence! ! !

ShapeImageViewAlmightyShapeImageView
showshow

Special function

1、ShapeImageView supports gradient rounded borders or rounded borders, unlimited image settings, perfectly compatible with all image loading libraries

2、 TheShapeImageView rectangular image supports the independent setting of the angle value of the four corners, and the rectangular border also supports the independent setting of the angle value of the four corners.

3、ShapeImageView supports four display modes: startCrop, endCrop, autoStartCenterCrop, autoEndCenterCrop

AutoStartCenterCrop and autoEndCenterCrop display mode can be automatically switched between startCrop and centerCrop (endCrop and centerCrop) after setting autoCrop_height_width_ratio

4、AlmightyShapeImageView is perfectly compatible with all image loading libraries, supports defining arbitrary graphics, only you can't think of it without it

The first step, the root directory build.gradle

dependencies {    implementation'io.github.flyjingfish:shapeimageview:1.5.7'}

The second step, instructions for use

一、ShapeImageView Instructions for Use

ShapeImageView example

<com.flyjingfish.shapeimageviewlib.ShapeImageViewandroid:id="@+id/iv_centerCrop"android:layout_width="110dp"android:layout_height="110dp"android:layout_marginStart="10dp"android:padding="10dp"app:FlyJFish_shape="rectangle"app:FlyJFish_shape_border="rectangle"app:FlyJFish_shape_border_width="3dp"app:FlyJFish_shape_border_angle="45"app:FlyJFish_shape_left_top_radius="8dp"app:FlyJFish_shape_right_top_radius="12dp"app:FlyJFish_shape_right_bottom_radius="16dp"app:FlyJFish_shape_left_bottom_radius="20dp"app:FlyJFish_shape_border_left_top_radius="10dp"app:FlyJFish_shape_border_right_top_radius="15dp"app:FlyJFish_shape_border_right_bottom_radius="20dp"app:FlyJFish_shape_border_left_bottom_radius="25dp"app:FlyJFish_shape_border_gradient="true"app:FlyJFish_shape_border_startColor="@color/purple_200"app:FlyJFish_shape_border_endColor="@color/teal_700"android:scaleType="centerCrop" />

Outer frame use

1,You need to set padding specially, otherwise some ScaleType of the picture will be filled with ImageView by default.

2,The color distribution of the gradient frame can be set throughsetGradientPositions, and the default null value is evenly distributed

3,Gradient color If you want to customize more colors, you can set it throughsetGradientColors

List of properties

attrformatdescription
FlyJFish_shapeenumThe picture is a rectangle/oval circle
FlyJFish_shape_radiusdimensionThe four corners of the image are rounded
FlyJFish_shape_left_top_radiusdimensionThe upper left corner of the image is rounded
FlyJFish_shape_right_top_radiusdimensionRound corners in the upper right corner of the image
FlyJFish_shape_right_bottom_radiusdimensionThe bottom right corner of the image is rounded
FlyJFish_shape_left_bottom_radiusdimensionThe bottom left corner of the image is rounded
FlyJFish_shape_start_top_radiusdimensionimage top left (Rtl: top right) corner rounded
FlyJFish_shape_end_top_radiusdimensionimage top right (Rtl: top left) corner rounded
FlyJFish_shape_end_bottom_radiusdimensionpicture bottom right (Rtl: bottom left) corner rounded
FlyJFish_shape_start_bottom_radiusdimensionpicture bottom left (Rtl: bottom right) corner rounded
FlyJFish_shape_borderenumThe background border drawing shape is none without drawing/rectangle rectangle/oval circle
FlyJFish_shape_border_radiusdimensionThe four corners of the background border are rounded
FlyJFish_shape_border_left_top_radiusdimensionThe top left corner of the background border is rounded
FlyJFish_shape_border_right_top_radiusdimensionrounded corners in the upper right corner of the background border
FlyJFish_shape_border_right_bottom_radiusdimensionThe bottom right corner of the background border is rounded
FlyJFish_shape_border_left_bottom_radiusdimensionThe bottom left corner of the background border is rounded
FlyJFish_shape_border_start_top_radiusdimensionbackground border top left (Rtl: top right) corner rounded
FlyJFish_shape_border_end_top_radiusdimensionbackground border top right (Rtl: top left) corner rounded
FlyJFish_shape_border_end_bottom_radiusdimensionbackground border bottom right (Rtl: bottom left) corner rounded
FlyJFish_shape_border_start_bottom_radiusdimensionThe bottom left (Rtl: bottom right) corner of the background border is rounded
FlyJFish_shape_border_colorcolor/referenceBackground border drawing color
FlyJFish_shape_border_gradientbooleanWhether the background border is drawn in gradient color
FlyJFish_shape_border_startColorcolor/referenceThe background border draw gradient color start color
FlyJFish_shape_border_centerColorcolor/referenceThe background border draws the gradient middle color
FlyJFish_shape_border_endColorcolor/referenceThe background border draws the gradient color end color
FlyJFish_shape_border_anglefloatStart angle of background border drawing gradient color
FlyJFish_shape_border_rtl_anglebooleanDoes the gradient start angle of the background border support mirror Rtl adaptation
FlyJFish_shape_border_strokeWidthdimensionwidth of background border drawing brush
FlyJFish_autoCrop_height_width_ratiofloatThe image aspect ratio is a multiple of the View aspect ratio
FlyJFish_shapeScaleTypeenumIf you set the new display mode to set this, the details are as follows:
FlyJFish_shapeScaleTypedescription
startCropCrop start top left
endCropCrop start bottom right
autoStartCenterCropAutomatically switch between startCrop and centerCrop
autoEndCenterCropAutomatically switch between endCrop and centerCrop

二、AlmightyShapeImageView Instructions for Use

AlmightyShapeImageView example(Built-in library ❤️ic_vector_heart 和 ⭐️ic_vector_star

The key to use is to set a graphic resource map (that is, FlyJFish_almighty_shape_resource). If you want to display a picture of any shape, you can achieve it as long as you set a resource map.

<com.flyjingfish.shapeimageviewlib.AlmightyShapeImageViewandroid:id="@+id/iv1"android:layout_width="110dp"android:layout_height="110dp"android:layout_marginStart="5dp"android:src="@mipmap/ic_launcher"app:FlyJFish_almighty_shape_resource="@drawable/ic_vector_heart"android:scaleType="centerCrop" />

List of properties

attrformatdescription
FlyJFish_almighty_shape_resourcereferenceShape Resource
FlyJFish_almighty_shape_scaleTypeenumThe display type of the drawing resource
FlyJFish_almighty_shape_scaleTypedescription
followImageViewKeepResourceScaleThe graphics resource follows the ImageView's ScaleType type and maintains the aspect ratio of the graphics resource
followImageViewFullImageThe graphics resource follows the ImageView's ScaleType but fills the width and height of the image (the graphics may be stretched relatively)
alwaysFixXYThe graphics resource will not follow the ScaleType of the ImageView, and always fill the ImageView container (setting this property to some ScaleType will cause the graphics to be incomplete)

Method

methodtypedescription
setShapeResourceDrawableShape Resource Drawable
setShapeResourceDrawableResShape resource id
setShapeScaleTypeShapeScaleTypeSets the display type for drawing graphics resources

Graphic resource setting prompt

FlyJFish_almighty_shape_resource is the image resource that allows the UI to export the graphics in advance. It can be a shape, a vector, or a png image, butIt is strongly recommended to use shape or vector vector graphics for better results

If you use png or svg resources, you can convert them to vector. For details, see my blog:

Extra episode: If you want to use network images for your graphics resource map (that is, not packaged into apk)

You can download network pictures through Glide and then callsetShapeResource to set the graphics

For example, download and set via Glide:

Glide.with(context).load("Internet connection").into(newCustomTarget<Drawable>() {@OverridepublicvoidonResourceReady(@NonNullDrawableresource,@NullableTransition<?superDrawable>transition) {imageView.setShapeResource(resource);    }@OverridepublicvoidonLoadCleared(@NullableDrawableplaceholder) {    }});

If you want to use the svg format map directly, you can do this(This is not recommended, because svg images can be directly converted into vector images,click here to view the conversion instructions)

Refer to the three-party analysis package

dependencies {    implementation'com.caverock:androidsvg-aar:1.4'}

Add the following two classes

publicclassSvgDecoderimplementsResourceDecoder<InputStream,SVG> {@Overridepublicbooleanhandles(@NonNullInputStreamsource,@NonNullOptionsoptions) {// TODO: Can we tell?returntrue;     }publicResource<SVG>decode(@NonNullInputStreamsource,intwidth,intheight,@NonNullOptionsoptions)throwsIOException {try {SVGsvg =SVG.getFromInputStream(source);if (width !=SIZE_ORIGINAL) {svg.setDocumentWidth(width);             }if (height !=SIZE_ORIGINAL) {svg.setDocumentHeight(height);             }returnnewSimpleResource<>(svg);         }catch (SVGParseExceptionex) {thrownewIOException("Cannot load SVG from stream",ex);         }     }}
publicclassSvgDrawableTranscoderimplementsResourceTranscoder<SVG,PictureDrawable> {@Nullable@OverridepublicResource<PictureDrawable>transcode(@NonNullResource<SVG>toTranscode,@NonNullOptionsoptions) {SVGsvg =toTranscode.get();Picturepicture =svg.renderToPicture();PictureDrawabledrawable =newPictureDrawable(picture);returnnewSimpleResource<>(drawable);     }}

New glide configuration

MyAppGlideModule

@GlideModulepublicclassMyAppGlideModuleextendsAppGlideModule {@OverridepublicvoidregisterComponents(@NonNullContextcontext,@NonNullGlideglide,@NonNullRegistryregistry) {registry                 .register(SVG.class,PictureDrawable.class,newSvgDrawableTranscoder())                 .append(InputStream.class,SVG.class,newSvgDecoder());     }@OverridepublicbooleanisManifestParsingEnabled() {returnfalse;     }}

Start using svg

  • local resources
Uriuri =Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE                         +"://"                         +getPackageName()                         +"/"                         +R.raw.dog_heart);GlideApp.with(this)         .as(PictureDrawable.class)         .transition(withCrossFade())         .load(uri).into(newCustomTarget<PictureDrawable>() {@OverridepublicvoidonResourceReady(@NonNullPictureDrawableresource,@NullableTransition<?superPictureDrawable>transition) {imageView.setShapeResource(resource);             }@OverridepublicvoidonLoadCleared(@NullableDrawableplaceholder) {             }         });
  • Internet resources
Uriuri =Uri.parse("http://www.clker.com/cliparts/u/Z/2/b/a/6/android-toy-h.svg");GlideApp.with(this)         .as(PictureDrawable.class)         .transition(withCrossFade())         .load(uri).into(newCustomTarget<PictureDrawable>() {@OverridepublicvoidonResourceReady(@NonNullPictureDrawableresource,@NullableTransition<?superPictureDrawable>transition) {imageView.setShapeResource(resource);             }@OverridepublicvoidonLoadCleared(@NullableDrawableplaceholder) {                         }         });

Common problem

  1. In some graphics, the pictures are not displayed completely after changing attributes such as rotation, rotationX, rotationY, etc.
  • Solution: Set the margin property to solve

Finally, I recommend some other libraries I wrote

About

🔥🔥🔥支持显示任意图形,只有你想不到没有它做不到;不直接操作Bitmap,可绘制圆形或圆角矩形背景边框,另外新增4种显示模式(Supports displaying arbitrary graphics, only you can't think of it, you can't do it without it; without directly operating Bitmap, you can draw a circular or rounded rectangle background frame, and add 4 new display modes)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2026 Movatter.jp