Android project combat (9): CustomShapeImageView Custom Shape ImageView

Original: Android project combat (9): CustomShapeImageView Custom Shape ImageView

A third-party class library that came out two years ago, with a variety of shapes of ImageView not limited to circular ImageView, necessary for project development

github download address: https://github.com/MostafaGazar/CustomShapeImageView

 

1. First, there is a third-party class library in the source code: library

First import Library into the project,

If not, you can look at the import method: Steps for importing library files in Eclipse and IDEA

2. There is a raw folder under the res folder in the source code and copy it to your own project (selective copy, which is some special graphics)

You can see that there are a bunch of files in .svg format.

SVG can be regarded as the most popular image file format at present. Here the author has written several special graphics for us. 

If you want to customize more shapes, you can learn SVG 

1. shape_5.svg pentagon

2. shape_circle_2.svg shell shape

3、shape_flower.svg 花形

4、shape_heart.svg 心形

5, shape_star star 1

6, shape_star star 2

7, shape_star star 3

 

3, the next step is to use

If we use the shape written in svg under the raw folder as the shape of the ImageView

Then: here is an app:svg_raw_resource="@raw/shape_star_3" Here is the one under the res/raw folder that specifies the shape of the image

1 <com.meg7.widget.SvgImageView
2 android:layout_width="50dp"
3 android:layout_height="50dp"
4 android:src="@drawable/hydrangeas"
5 app:svg_raw_resource="@raw/shape_star_3"
6 android:scaleType="centerCrop" />

Here comes the point:

In actual development, the most commonly used one is the circular image, so the above are all special graphics, what should I do if I want to use a circular ImageView?

Look at the class library, several source code

BaseImageView.java is the base class

The CircleImageView.java class is a class that inherits BaseImageView.java and is used for circular ImageView

Use: This is simple, use the same as ordinary ImageView, the label has changed

1 <com.meg7.widget.CircleImageView
2 android:layout_width="100dp"
3 android:layout_height="100dp"
4 android:src="@drawable/hydrangeas"
5 android:scaleType="centerCrop" />

Rectangle ImageView : RectangleImageView.java

1 <com.meg7.widget.RectangleImageView
2 android:layout_width="100dp"
3 android:layout_height="100dp"
4 android:src="@drawable/hydrangeas"
5 android:scaleType="centerCrop" />

The above is the main part that is needed.

In the source code, CustomShapeImageView.java looked at the source code. It is an ImageView that displays circular images by default. There are circles, squares, and custom shapes. It depends on the situation. Personally, the above are enough to use.

related information:

Custom circular image

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325033949&siteId=291194637