When using a RecyclerView, is it possible to set the item height to be that of two text lines?
Suppose an item has a TextView on it. Some items might have a long text that does not fit in one line. I will restrict the maximum number of lines to 2. However, if some items have 1-line height and others have 2-line height, it would look ugly. Therefore, I want all items to have the height of 2-lines, even though the item has only one line of text.
I can set height of an item in DP, but the problem is that since I use system font settings, hard-coding a numeric value for height should be bad. Some systems may have large fonts with large margins.
Is what I am trying to do possible?
have you tried: android:lines="2" in xml? according to doc: Makes the TextView be exactly this many lines tall.
There is a option you can set minimum height of textView. android:minHeight="50dp"
or you can add this android:lines="2"
to your xml code.
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:text="Hello"
android:textSize="20sp"
android:lines="2"/>
Now android:layout_height="wrap_content"
will manage font size.. 20sp or 50sp or any size of system font it wouldn't be a problem..
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With