Share a special method for Android to set up a circular picture _android

Source: Internet
Author: User

CardView with ImageView display Circular Chart effect chart:

Just looking at the custom View knowledge point, suddenly remembered that if the width is CardView equal, CardView set the radius of the fillet is half the width of the height, is not a circle?!

1. layout file

<android.support.v7.widget.cardview
 android:id= "@+id/cv_img_activity"
 android:layout_width= "200DP"
 android:layout_height= "200DP"
 app:cardcornerradius= "100DP"
 app:cardelevation= "10DP"
 app: Cardpreventcorneroverlap= "true" >

 <imageview
  android:id= "@+id/iv_cv_img_activity"
  android: Layout_width= "Match_parent"
  android:layout_height= "match_parent" android:scaletype= "CenterCrop"
  />
 <textview
  android:layout_width= "wrap_content"
  android:layout_height= "Wrap_content"
  Android:textcolor= "@color/coloraccent"
  android:textsize= "30sp"
  android:layout_gravity= "Bottom|center _horizontal "
  android:text=" Circle "/>
</android.support.v7.widget.CardView>

CardViewInherited FramLayout . Width and height are 200dp, set fillet radius to 100DP

Code in 2.Aciticy

Use the glide for picture loading

 public class Imgactivity extends Appcompatactivity {private static final String URL = "Https://timgsa.baidu.com/timg?image&quality=80&size=b10000_10000&sec=1473082549776&di= cb9749bd976beb119da065ee56ebbc60&imgtype=jpg&src=http%3a%2f%2fstatic.oneplus.cn%2fdata%2fattachment%
 2fforum%2f201410%2f18%2f111437v9ll9869qqmq76n7.jpg ";
 Private CardView CardView;
 Private ImageView IV_CV;
  @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
  Setcontentview (R.LAYOUT.ACTIVITY_IMG);
 Init ();
  private void Init () {CardView = (CardView) Findviewbyid (r.id.cv_img_activity);
 IV_CV = (ImageView) Findviewbyid (r.id.iv_cv_img_activity);
  @Override public void Onwindowfocuschanged (Boolean hasfocus) {super.onwindowfocuschanged (hasfocus); if (hasfocus) {Glide.with (imgactivity.this). Load (URL). Override (Cardview.getwidth (), Cardview.getheight ()). into (iv
  _CV); }
 }

}

onWindowFocusChanged(boolean hasFocus)This method can be used to determine Activity whether the focus has been achieved, this time to get the control width and height, is to get the control of the height of the method.

3. Summary

Used to be a custom CircleImageView , and if you just want a circular graph, this method can also be considered for use. I wonder if anyone has used this method. It is also convenient to add text on the diagram. It's a little easier to feel this way. The above is the entire content of this article, I hope that the development of everyone can help.

Related Article

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.