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?
Asked
Active
Viewed 851 times
2

a_local_nobody
- 7,947
- 5
- 29
- 51

Sanjid Chowdhury
- 1,010
- 1
- 5
- 9
-
Use `android:maxHeight` to set the maximum height that you want the `ScrollView` to be. – CommonsWare Feb 26 '21 at 12:07
-
I have set `android:layout_height="wrap_content"` and `android:maxHeight= "100dp"` to my `ScrollView`, but it is not working – Sanjid Chowdhury Feb 26 '21 at 14:46
-
We have no way to know what "it is not working" means, sorry. – CommonsWare Feb 26 '21 at 14:55
-
The android:maxHeight for ScrollView is not working with android:layout_height = "wrap_content". If the text content in the ScrollView exceeds the maxHeight, it does not limit it. Am i doing something wrong here? – Sanjid Chowdhury Feb 26 '21 at 23:46
-
1I cannot answer that. You might want to edit your question and provide a [mcve]. Show us the complete layout, including the `ScrollView` and the `TextView`, and perhaps we may see something. – CommonsWare Feb 27 '21 at 00:26
2 Answers
4
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

a_local_nobody
- 7,947
- 5
- 29
- 51
0
You can wrap your code into LinearLayout with wrap_content option and on inner structure you can set android:layout_weight="1"

user3913101
- 1
- 1