Hi All,
I have a list of locations in a ListView and I need to display an arrow image that is rotated to the correct direction that each location is in from my current location. At this stage I am targeting Android (API V 14 and above) devices so I have been able to work out the Rotation Degrees using a method similar to this StackOverflow question, but I cannot find a way to rotate the image in the ImageCell in the ListView.
I am creating the ListView using the following code:
var list = new ListView {
RowHeight = 40
};
list.ItemsSource = vm.Locations;
var cell = new DataTemplate(typeof(MyImageCell));
cell.SetBinding(TextCell.TextProperty, "Address");
cell.SetBinding(ImageCell.ImageSourceProperty,"Image");
list.ItemTemplate = cell;
where the Image Property is defined in the View Model as:
public ImageSource Image {
get {
return ImageSource.FromResource ("MyApp.images.directionArrow.png");
}
}
And MyImageCell is defined as:
public class MyImageCell : ImageCell
{
public MyImageCell()
{
}
}
I created MyImageCell because I am using the following custom Renderer (based on the Monkeys sample at GitHub:
public class MyImageCellRenderer: ImageCellRenderer
{
protected override Android.Views.View GetCellCore(Cell item, Android.Views.View convertView, Android.Views.ViewGroup parent, Context context)
{
var cell = (LinearLayout)base.GetCellCore(item, convertView, parent, context);
var image = (ImageView)cell.GetChildAt(0);
image.SetScaleType(ImageView.ScaleType.CenterCrop);
return cell;
}
}
I did notice that the Image class has a RotateTo property, but I couldn't see how to set the source of an ImageCell to an Image Object.
Can someone please tell me if it is possible for me to achieve the image rotation that I am after, and if it is, provide some guidance on this?
Thanks in advance.
PS Sorry if I have put too much detail in this post, but I would rather provide too much detail than not enough.