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>
CardView
Inherited 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.