I'm trying to force a drawn view to be in an exact dimension. No matter how I try it ignores the dimensions.
Code:
My view to be drawn in 250x250 pixels:
public class MyCustomView extends View {
public MyCustomView(Context context) {
super(context);
}
public MyCustomView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
FlowLayout layout = new FlowLayout(getContext());
for (int i = 0; i < 30; i++) {
TextView textView = new TextView(getContext());
textView.setText("[text#" + i + "]");
textView.setBackgroundColor(Color.GREEN);
layout.addView(textView);
}
int dimension = 250;
layout.measure(
dimension,
dimension);
layout.layout(0, 0,
dimension,
dimension);
layout.draw(canvas);
}
}
Result:
The layout clearly not renders in 250x250 pixels.
If I swap the FlowLayout to a standard Android SDK layout, like to a Linear Layout, the result is the same.
Please help if you can.