Android Question Xui appCompat Cards example question

John Decowski

Member
Licensed User
Longtime User
Does anyone know if it is possible to change the height of the "cards" in the cards example during run time? I want to make an expandable card.
Thanks in advance.
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
The height of the card is determined by the height of the panel. The code provided already does this.
Note, the height for setlayoutanimated is determined by the approximatescreensize.


B4X:
Private Sub CreateItem(Width As Int, Title As String, Image As String, Content As String) As Panel
    Dim p As B4XView = xui.CreatePanel("")
    Dim height As Int = 280dip
    If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then height = 310dip

    p.SetLayoutAnimated(0, 0, 0, Width, height)
    p.LoadLayout("Card1")
    
    lblTitle.Text = Title
    lblContent.Text = Content
    SetColorStateList(lblAction1, xui.Color_LightGray, lblAction1.TextColor)
    SetColorStateList(lblAction2, xui.Color_LightGray, lblAction2.TextColor)
    ImageView1.SetBitmap(xui.LoadBitmapResize(File.DirAssets, Image, ImageView1.Width, ImageView1.Height, True))
    Return p
End Sub
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Or you can set the height based on a textfield, in this example, the panel height is set based on the height of the textfield, plus the title which is above it. I pulled this from a larger app, but it should point you in the right direction.
MessageSingle contains a title label and a description label

B4X:
Sub BuildMessage(w As Int, NewMsg As Boolean,msg As MKCCM_Message) As Panel
    Private p As Panel
    
    p.Initialize("")
    Activity.AddView(p,0,0,w,100dip)
    p.LoadLayout("MessageSingle")
    p.RemoveView
    
    p.Color = Colors.Transparent
    
    
'    Log("Message Height = "& lblMessageBody.Height)
    lblMessageDesc.Text = msg.Body
    Private su As StringUtils
    lblMessageDesc.Height =  su.MeasureMultilineTextHeight(lblMessageDesc,lblMessageDesc.Text)
'    Log("Message Height = "& lblMessageBody.Height)

    p.Height = lblMessageTitle.Height + lblMessageDesc.Height + 20dip
'        Log("Panel height = "&p.Height )
    Return p
End Sub
 
Upvote 0
Top