Krishanu Dey
Krishanu Dey

Reputation: 6406

How to set minimum width of a view to match parent

I'm creating some custom views and drawing everything required in canvas.
I can calculate the minimum width required to draw my view. But I need to follow the following rules,

Parent is inside ScrollView.

Parent is extended from LinearLayout with a vertical orientation.

Source code available on request.

Upvotes: 2

Views: 1852

Answers (1)

Darish
Darish

Reputation: 11481

if view's required width is less than parent's width, set view width to parent width.

if view's required width is more than parent's width, set parent's width to view's width.

Keep child width as always match_parent and all you have to do is adjust the parent layout width. It will do the magic for you :)

Upvotes: 1

Related Questions