In the visual editor, you can set the width and height of the View.
How do I get the width and height?
I understand you need to use the attrs.get method, but I don’t know which one to select and which parameters to specify as input.
need to get layout_width
ViewGroup.LayoutParams layoutParams = this.getLayoutParams(); layout_width=layoutParams.width; layout_height=layoutParams.height; Not working, I want to get the width and height
public class ShapeView extends TextView { Paint paint; int layout_width=0,layout_height=0; public ShapeView(Context context, AttributeSet attrs) { super(context, attrs); paint=new Paint(); paint.setColor(Color.BLUE); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ShapeView); paint.setColor(a.getColor(R.styleable.ShapeView_shapeColor, 0xFF000000)); paint.setStyle(Paint.Style.FILL_AND_STROKE); a.recycle(); this.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); layout_width = this.getMeasuredWidth(); layout_height = this.getMeasuredHeight(); Log.e("asd",layout_width+" "+layout_height); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawCircle(layout_width,layout_height,layout_width,paint); } } Pointed 50dp height and width
In the code indicated the canvas.drawCircle(50, 50, 50, paint);
As a result, got it, chtoli bug?

canvas.getHeight();returns pixels in height - georgehardcore