A third-party class library that came out two years ago, with a variety of shapes ImageView not limited to circular imageview, a must for project development
Github:https://github.com/mostafagazar/customshapeimageview
1, first of all the source code has a third-party class libraries: library
To import the library into the project first,
No, you can look at the import method: about Eclipse and idea importing library files
2, the source in the Res folder has a raw folder copied to its own project (selective replication, is some special graphics)
You can see that there's a bunch of. svg formatted files.
SVG can be considered the most hot picture file format, where the author has written us a few special graphics
If you want to customize more shapes, you can learn the following SVG
1, shape_5.svg Pentagon
2. Shape_circle_2.svg Shell shape
3. Shape_flower.svg Flower Shape
4. Shape_heart.svg Heart Shape
5, Shape_star star shape 1
6, Shape_star star shape 2
7, Shape_star star shape 3
3, the next is the use of
If we use the SVG-written shape under the raw folder as the shape of the ImageView
Then: Here is a app:svg_raw_resource= "@raw/shape_star_3" Here is the specified picture shape under the Res/raw folder which
1<Com.meg7.widget.SvgImageView2Android:layout_width="50DP"3android:layout_height="50DP"4Android:src="@drawable/hydrangeas"5App:svg_raw_resource="@raw/shape_star_3"6Android:scaletype="Centercrop"/>
Here's the point:
The actual development, the most commonly used is the circular picture, then the above several are special graphics, to use the circular imageview how to do?
Look at the class library, several source code
Baseimageview.java is the basic class
The Circleimageview.java class is a class that inherits Baseimageview.java, and is used for circular ImageView
Use: This is simple, and ordinary imageview like the use, the label has changed
1 <com.meg7.widget.CircleImageView2 android:layout_width="100dp " 3 android:layout_height="100dp"4 android:src="@ Drawable/hydrangeas"5 android:scaletype="centercrop" />
Rectangular ImageView:RectangleImageView.java
1 <com.meg7.widget.RectangleImageView2 android:layout_width="100DP "3 android:layout_height="100dp"4 android:src= "@drawable/hydrangeas"5 android:scaletype="centercrop " />
The above is the main part of the need.
SOURCE Customshapeimageview.java See the next source is the default display circular picture of the ImageView, there is a circle, square, custom shape, see the situation used, personal feeling, the above several use up is enough.
Related knowledge:
Custom circular Picture
Third-party Class library learning notes: Customshapeimageview Custom Shape ImageView