This question is locked. New answers and comments are not allowed.
I want to create a ListView which will have a multiline label. This label will have n number of lines. So, I want the ListView to adapt its ItemSize according to the height of Label. How can I achieve this?
Please provide code in C# as I am using Xamarin.
Please provide code in C# as I am using Xamarin.
5 Answers, 1 is accepted
0
Hi,
You can easily do that with the following steps:
1. Set the dynamicItemSize property of the list layout to true
2. Provide a custom cell for the listview by inheriting from TKListViewCell
You can check out our sdk examples, we have example for creating list with variable item size, here is link to the repo.
Regards,
Sophi
Telerik
You can easily do that with the following steps:
1. Set the dynamicItemSize property of the list layout to true
2. Provide a custom cell for the listview by inheriting from TKListViewCell
You can check out our sdk examples, we have example for creating list with variable item size, here is link to the repo.
Regards,
Sophi
Telerik
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items
0
Philipp
Top achievements
Rank 1
answered on 25 Jul 2016, 01:53 PM
Can't find this property in TKListViewLinearLayout. Is their any way to get a dynamic height in Xamarin?
I'm using 2016.2.708.1 and latest Xamarin.
0
Hi Philipp,
Did you cast your layout object to TKListViewLinearLayout before accessing dynamicItemSize property.
Consider the following snippet.
In case this does not cover your scenario, write back any time.
Regards,
Sophi
Telerik by Progress
Did you cast your layout object to TKListViewLinearLayout before accessing dynamicItemSize property.
Consider the following snippet.
var layout = list.Layout as TKListViewLinearLayout;
layout.DynamicItemSize = true;
Regards,
Sophi
Telerik by Progress
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items
0
Philipp
Top achievements
Rank 1
answered on 28 Jul 2016, 09:20 AM
How do I set the height of the single cell. The change of height in the CustomCell has no effect. She remains at an altitude of 1000.
0
Hi Phillip,
You can set explicit height or dynamic size of the labels with a custom cell. The idea behind implementing dynamic layouts is that you are setting the dynamicItemSize property to true in order to notify the TKListView that the provided cell will be with dynamic layout. So you need to create a custom cell and specify it's layout logic. Good example is one of our SDK examples, we have created a cell with dynamic size based on the height of the textLabel. Consider following snippet.
In case this is not what you want, please send us some screenshots of the desired result or provide us with a bit more detailed description of what you are trying to achieve.
Regards,
Sophi
Telerik by Progress
You can set explicit height or dynamic size of the labels with a custom cell. The idea behind implementing dynamic layouts is that you are setting the dynamicItemSize property to true in order to notify the TKListView that the provided cell will be with dynamic layout. So you need to create a custom cell and specify it's layout logic. Good example is one of our SDK examples, we have created a cell with dynamic size based on the height of the textLabel. Consider following snippet.
class ListViewDynamicSizeCell: TKListViewCell {
var label: UILabel?
override init(frame: CGRect) {
super.init(frame: frame)
label = UILabel(frame: CGRect.zero)
label!.translatesAutoresizingMaskIntoConstraints = false
label!.numberOfLines = 0
self.addSubview(label!)
let views = [ "v": label! ]
self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-10-[v]-10-|", options:NSLayoutFormatOptions(rawValue:0), metrics: nil, views: views))
self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-10-[v]-10-|", options:NSLayoutFormatOptions(rawValue:0), metrics: nil, views: views))
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
self.label!.preferredMaxLayoutWidth = self.bounds.size.width-20
super.layoutSubviews()
}
}
In case this is not what you want, please send us some screenshots of the desired result or provide us with a bit more detailed description of what you are trying to achieve.
Regards,
Sophi
Telerik by Progress
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items