I'd like to make myself a ListView with rows showing the name and the price of some product horizontally aligned.
I want to the price to get the width it needs and the name to wrap to a new line if width is running out.
So I used a horizontal LinearLayout, but name and price were overlapping. So I tried this LinearLayout space distribution solution but that way name and price are both wrapped.
Is there a way to have a 'take what you need' + 'take whats left' distriubtion?
LinearLayout is good when you know, how exactly you want to divide the space, either in a ratio or equally.
The described layout can better be achieved using
RelativeLayout.NOTE : You may want to use
minWidthattribute to your name TextView, so that if price text becomes lengthy enough to cover whole width, name TextView is not pushed out of screen.Sample Outputs:
However, if you still want to use
LinearLayoutyou can limit the size of name TextView usingmaxWidthproperty. But in this case if price text is small, your name text will still go to next line as you defined maximum width. But this won't happen in case ofRelativeLayout.