Not able to Draw the circle in Custom View android using onDraw(canvas) function? -


i not able draw circle using custom views in android. doesn't work, though basic code implementation, not working. can me same?

this custom view class implementation:

public class customview extends view {     private paint paint;     private int color;     private float radius;      public customview(context context) {         super(context);         init();     }      public customview(context context, @nullable attributeset attrs) {         super(context, attrs);         typedarray ta = context.obtainstyledattributes(attrs, r.styleable.customview);               color = ta.getcolor(r.styleable.customview_circlecolor, color.black);         radius = ta.getfloat(r.styleable.customview_circlesize, 200f);         ta.recycle();         init();     }      @override     protected void ondraw(canvas canvas) {         super.ondraw(canvas);         canvas.drawcircle(getwidth() / 2, getheight() / 2, radius, paint);      }      private void init() {         paint = new paint();         paint.setcolor(color);     }      public customview(context context, @nullable attributeset attrs, int defstyleattr) {         super(context, attrs, defstyleattr);     } } 

and mainactivity implementation:

  public class mainactivity extends appcompatactivity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);      } 

this attr.xml file:

    <?xml version="1.0" encoding="utf-8"?> <resources>      <declare-styleable name="customview">         <attr name="circlecolor" format="color"></attr>          <attr name="circlesize" format="enum">              <enum name="small" value="100"></enum>             <enum name="medium" value="300"></enum>             <enum name="large" value="600"></enum>          </attr>     </declare-styleable>  </resources> 

and activity_main.xml file:

    <?xml version="1.0" encoding="utf-8"?> <framelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context="com.hp.customviews.mainactivity">      <com.hp.customviews.customview         android:layout_width="match_parent"         android:layout_height="match_parent"         app:circlecolor="#009688"         app:circlesize="medium"         android:visibility="gone" />    </framelayout> 

what doing wrong? why code not working? please me this.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -