Anyway to keep the height of a layout as wrap content, but not let it exceed a certain height

Viewed 389

I have a ScrollView that contains a TextView which is fetched dynamically from a data base. If the text is small in length, I want my ScrollView layout_height to wrap content, however if the text length is big, I want the ScrollView layout_height to be fixed to a certain value (such as 200dp). Is there anyway to achieve this?

2 Answers

Perhaps you're looking for

 android:minHeight="12dp" 
 android:maxHeight="200dp"

just some example values, you don't have to use both, but you can set maxHeight to a certain value so that the view never exceeds those values and perhaps minHeight so that it doesn't collapse entirely, unless you want that, in which case just remove minHeight

You can wrap your code into LinearLayout with wrap_content option and on inner structure you can set android:layout_weight="1"

Related