I have a RelativeLayout
and i want it to fill the whole width of the view, but if it would become bigger than xx dip
it should stay in this size.
I tried to use android:maxWidth="xxdp"
but it is not working with match_parent
.
Asked
Active
Viewed 5,406 times
3

AdrianoCelentano
- 2,461
- 3
- 31
- 42
-
2what's wrong with `android:layout_width="xxdip"` ? – Blackbelt Jun 19 '14 at 13:01
-
1then the layout is always xxdip and on smaller devices it is outside of the window instead of match_parent – AdrianoCelentano Jun 19 '14 at 13:06
-
with which attributes ? – AdrianoCelentano Jun 19 '14 at 13:10
-
1to override width, I mean. You can have values/styles, and define width=xxdip but for smaller devices where do you define match_parent – Blackbelt Jun 19 '14 at 13:12
-
k thats what i just did too, i was hoping for some more flexible solution, but i guess it will be fine, cheers – AdrianoCelentano Jun 19 '14 at 13:16
-
Possible duplicate of [maxWidth doesn't work with fill\_parent](http://stackoverflow.com/questions/13325403/maxwidth-doesnt-work-with-fill-parent) – Kirill Rakhman Aug 19 '16 at 10:23
1 Answers
-2
Rather than setting width to match_parent
, set the width to "0dp"
and the weight of the layout to 1.0f
.
Assuming there are no other views in the same parent, this should force the RelativeLayout
to fill the width. maxWidth
should now work like you expected.

JRad the Bad
- 511
- 5
- 25