Android Question CustomListview row height

taylorw

Active Member
Licensed User
Hi all,I have a problem using CustomListview.
Below you can see the two screen shoot, how can i make CustomListview row height will follow the device height to change?
 

Attachments

  • False.png
    False.png
    17.7 KB · Views: 419
  • True.png
    True.png
    32.5 KB · Views: 429

taylorw

Active Member
Licensed User
Hi Erel, no same as the activity height, is if in different device the row height are not same, you can see the first post.
The "false.png" the row height too height, can make it look like "True.png"?

B4X:
Dim RowHeight As Double
RowHeight = ((1740 - 100%y)/8.8) + 120

B4X:
Listview_Car.Add(CreateListItem(M.Get("Car"),Listview_Car.AsView.Width,RowHeight),RowHeight,M.Get("Car"))

B4X:
Sub CreateListItem(Car As String, Width As Int, Height As Int) As Panel
    Dim p As Panel
    
    p.Initialize("")
    Activity.AddView(p, 0, 0, Width, Height)
    p.LoadLayout("Custom_Car_List")
    p.RemoveView
    'label1 and button1 will point to the last added views.
    lblCar.Text = Car
    Line.Top = Height - 1
    Return p
    
    
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
This looks wrong to me:
RowHeight = ((1740 - 100%y)/8.8) + 120
What is 1740 ?
You must use dip values and not pure pixels!
RowHeight = ((1740dip - 100%y)/8.8) + 120dip
If 1740 is the height of a view, you should use viewxxx.Height instead of 1740.

In this line
Listview_Car.Add(CreateListItem(M.Get("Car"),Listview_Car.AsView.Width,RowHeight),RowHeight,M.Get("Car"))
you have one parameter more than in this line !?
Sub CreateListItem(Car As String, Width As Int, Height As Int) As Panel
 
Upvote 0

taylorw

Active Member
Licensed User
Sorry for late reply, the 1740 is my phone screen Height.
"RowHeight = ((1740 - 100%y)/8.8) + 120" This is some formula to calculate the different device height to get the row need to set how many height.
@Erel , @klaus
Your guys how to set the CustomeListview row height? Can teach me?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
To give a concrete answer you must give us more information.
What exactly did you want to achieve with your equation?
As an example:
If your device has a screen height of 1740 pixels, then:
1740 - 100&y would be equal to ZERO, therefore Height would be 120 pixels.
Then, if you had a device wih a screen height of 740 pixels
Height would be equal to 233!
So, what exactly do you want to achieve with your equation?
Why do you want to adjust the item height according to the screen height?
It seems that you add just one Label, so could use Listview_Car.AddTextItem, the height is adjusted automatically.
 
Upvote 0

taylorw

Active Member
Licensed User
Thanks @Erel,I will read it.

@klaus for this question <So, what exactly do you want to achieve with your equation?>,
I don't want look like thick.
upload_2017-12-20_7-15-17.png


Then this look like thin.

upload_2017-12-20_7-16-55.png


Thanks for your time!Best Regards!
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
It depends on what you want to put in a single Item!

If it contains only one label or anyway views on a single line (item, row or call it how you want), you could set the height of the item to 45-50dips.

So, if each item must contain two "rows" of views (labels, edittexts, not big imageview), you could set the height of the item to 90-100dip.

Otherwise you could use something like:

ItemHeight = Max(50dip, CLVHeight / 10)

assumed that on a device 10 items are fine (in this way you would get stretched items, which does not like to everyone ;))


Useful thread? I opened it and wrote there; so... I don't remember :D
https://www.b4x.com/android/forum/threads/designer-minimum-layout-height-b4a-5-80.65153/
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
I understant what you want.
My question was about the logic behind your equation.
Why 1740 - 100&y ?
Why /8.8 ?
I would use a fixed height.
Can't you post a small project, so we could see what exactly you have done and how and therefore could give you a concrete advice.
 
Upvote 0
Top