Long text cut ListView Item

desof

Well-Known Member
Licensed User
Longtime User
:sign0085:

hi in my text when long looks like? could not fix it in any way?
 

Attachments

  • cutText.jpg
    cutText.jpg
    14.2 KB · Views: 475
Last edited:

Harris

Expert
Licensed User
Longtime User
ListViews are typically used for short statements. That said, they can be used with longer lines of text providing you take control with labels that replace the views label. As you will find with even longer lines of text, the example below has its' limits.

Try this:

B4X:
' set the listview to fit entire screen
LV1.SetLayout(0, 0, 100%x, 100%y)

' set the background to transparent when using gradiant or images
   LV1.ScrollingBackgroundColor = Colors.Transparent

' dim two labels - one for first line and one for second line of listview
' now we will have control over the text in the listview
   Dim lbl1,lbl As Label

' the first line is assigned to our frist label   
   lbl = LV1.TwoLinesAndBitmap.Label

' set color to white
   lbl.TextColor = Colors.White
   
' assign the second line label   
   lbl1 = LV1.TwoLinesAndBitmap.SecondLabel

' usually, the second line contains more text. Here we set the height 
' of the secondlabel to allow it to show the wrapped text
   LV1.TwoLinesAndBitmap.SecondLabel.Height = 100dip

' I find that the text won't wrap properly unless we make the line narrower 
' than  the full width
    LV1.TwoLinesAndBitmap.SecondLabel.Width  = LV1.Width - 50dip
   lbl1.TextColor = Colors.Yellow


' the following determines if device is a phone or tablet with a 
' GetDevicePhysicalSize function that Klaus created (below)
' Now we set the listviews height so the wrapped text has a place to show
' Remember - set the (second) label height and the listview itemheight
' set the text size according to device

    If DefCM.GetDevicePhysicalSize < 6 Then
       LV1.TwoLinesAndBitmap.ItemHeight = 70dip
      lbl.TextSize = 18
      lbl1.TextSize = 14

   Else
       LV1.TwoLinesAndBitmap.ItemHeight = 80dip
      lbl.TextSize = 24
      lbl1.TextSize = 18
   
   End If


Sub GetDevicePhysicalSize As Float
   Dim lv As LayoutValues

   lv = GetDeviceLayoutValues
   Return Sqrt(Power(lv.Height / lv.Scale / 160, 2) + Power(lv.Width / lv.Scale / 160, 2))
End Sub
 
Upvote 0
Top