I have a custom view which contains a simple canvas(rectangle)
I want to adapt the width and height of this custom view to the canvas width and height
Because when using wrap_content
the custom view fills all the screen space
Thank you very much
Layout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<com.dev.ui.RectangleView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
Custom view:
public class RectangleView extends View {
Paint paint = new Paint();
public SquareLegendView(Context context) {
super(context);
}
public SquareLegendView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareLegendView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
paint.setColor(Color.BLACK);
canvas.drawRect(40, 40, 80, 80, paint);
//drawRect(left, top, right, bottom, paint)
}
}