【发布时间】:2019-11-17 21:36:43
【问题描述】:
我有问题。我用这样的 ListView 创建了一个 ContentPage:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="MyApp.HomePage">
<ContentPage.Content>
<StackLayout>
<ListView x:Name="ListViewMain">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Text="Employee Name" Grid.Column="1" Grid.Row="0" HorizontalOptions="Start"/>
<Image Source="VoteUp.png" VerticalOptions="End" Grid.Row="1" Grid.Column="0"/>
<Image Source="VoteDown.png" VerticalOptions="Start" Grid.Row="2" Grid.Column="0"/>
<Image Source="{Binding image}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1" Grid.RowSpan="2" BackgroundColor="AliceBlue" VerticalOptions="Fill" HorizontalOptions="Fill"/>
<Image Source="Favorite.png" Grid.Row="3" Grid.Column="1" HorizontalOptions="Start"/>
<Image Source="Send.png" Grid.Row="3" Grid.Column="1" HorizontalOptions="End"/>
<Image Source="Save.png" Grid.Row="3" Grid.Column="2" HorizontalOptions="End"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
这是页面构造函数:
public HomePage()
{
InitializeComponent();
ListViewMain.ItemTemplate = new DataTemplate(typeof(CustomViewCell));
}
这里是 CustomViewCell:
public class CustomViewCell: ViewCell
{
public CustomViewCell()
{
//instantiate each of our views
var image = new Image();
image.SetBinding(Image.SourceProperty, "Example_Image.jpg");
}
}
我将所有图标图片添加到android路径下的drawable文件夹中,但是当我启动应用程序时,整个页面都是空白的,根本没有图片。我做错了什么?
编辑
现在我在 ListView 中添加了一个 ListSource,但是我的结果非常小:
如何使行变大?
【问题讨论】:
-
把你的图片放在drawable-hdpi文件夹中
标签: android xamarin xamarin.android xamarin.ios