How can i show a simple list view without that size element and element Labels?
From 2020.1 onwards, you can use listView.showBoundCollectionSize = false;
to hide the first size element of the list.
By default, the ListView’s SerializedObject binding will create PropertyFields which have labels. If you create your own makeItem delegate, you can control how things will be displayed:
listView.makeItem = () =>
{
var container = new VisualElement();
container.Add( new TextField(){binding-path = "Name"});
container.Add( new TextField(){binding-path = "Test"});
}
You can set the TextField.label or change TextFields to PropertyFields in the above example to have the labels on the left.
Mhm this gives me a warning that it can’t bind Array.size, so implemented the bindItem callback:
var itemArrayProperty = serializedObject.FindProperty("_items");
list.makeItem += () =>
{
var entry = _entryTree.CloneTree();
return entry;
};
list.bindItem += (element, i) =>
{
if (i == 0)
{
element.Clear();
var label = new Label("This is just a label");
element.Add(label);
return;
}
var p = itemArrayProperty.GetArrayElementAtIndex(index: i-1);
var entry = element as TemplateContainer;
entry.BindProperty(p);
var deleteButton = entry.Q<Button>("DeleteButton");
deleteButton.clicked += () =>
{
((ItemManager) target).RemoveItem(i-1);
EditorUtility.SetDirty(target);
};
};
Is there a way to hide it this way? Setting its style to hidden just leaves an empty space, without the items moving up. Moving it to the end also effects the list height.
Is it possible to have different heights for the items? (no)
Listview items need to be the same height. In your case, in your bindItem, you have to ensure that you can handle the visualElements in any previous state. By clearing elements and replacing with a label, this will cause problems when scrolling down, since this element will be recycled and bound to another index later.
If you don’t need to display really long lists of elements, maybe using a ScrollView directly would do.