Android round picture

Source: Internet
Author: User

Reference 1 2 3 4

One, custom view inherit ImageView file

New Attr.xml Copy code under Value folder

1<?xml version= "1.0" encoding= "Utf-8"?>2<resources>3<declare-styleable name= "Shapedimageview" >4<attr name= "Shape_mode" format= "enum" >5<enumName= "Round_rect" value= "1"/>6<enumName= "Circle" value= "2"/>7</attr>8<attr name= "Round_radius" format= "Dimension"/>9<attr name= "Stroke_width" format= "Dimension"/>Ten<attr name= "Stroke_color" format= "Color|reference"/> One</declare-styleable> A</resources>
attr

Copy the Shapedimageview.java file to the View folder

Add xmlns:app= "Http://schemas.android.com/apk/res-auto" under the layout file to create a

Round app:shape_mode= "Circle" app:stroke_color border color app:stroke_width border size

1     <Com.xxxx.view.ShapedImageView2         android:id= "@+id/iv_circle5"3         android: Layout_width= "100DP"4         android:layout_height= "100DP"5         android:scaletype= "Centercrop" 6         App:shape_mode= "Circle"7         />

Corner Rectangle app:shape_mode= "Round_rect" App:round_radius rectangle radian app:stroke_color Border color app:stroke_width border size

1     <Com.xxxx.view.ShapedImageView  2         android:id= "@+id/iv_circle6" 3         android: Layout_width= "100DP" 4         android:layout_height= "100DP" 5         android:scaletype= "Centercrop" 6         App:shape_mode= "Round_rect" 7         app:round_radius= "20DP" 8         app:stroke_width= "5DP" 9         App:stroke_color= "#1E90FF"ten          />

It is worth mentioning that android:scaletype= "Centercrop" if not set to get the network picture will have a problem with the local picture no problem but it's best to set

Universalimageloader Glide can load normally

Second, Glide bitmaptransformation

Round Glidecircletransform

Angular Rectangle Glideroundtransform

Add these 2 files to the project folder

And then use it in glide.

Glide.with (this). Load (IMAGEURL1). Transform (new  glidecircletransform (context)). into ( IMAGEVIEW1); Glide.with (this). Load (IMAGEURL2). Transform (new  glideroundtransform (context)). into ( IMAGEVIEW2); Glide.with (this). Load (IMAGEURL2). Transform (new glideroundtransform (context,10)). into ( IMAGEVIEW3);

But it has no border effect and can only be glide.

Android round picture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.