【问题标题】:The cell doesnt show a complete image单元格不显示完整的图像
【发布时间】:2018-01-06 08:38:59
【问题描述】:

我想做一个黄色背景的单元格和一个带有文本的橙色框和一个中等大小的图像,但它不起作用。图片看起来不大,我不能使用边距

这是我的 XAML

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="neoFly_Montana.Views.PromocoesView"
         BackgroundImage="promocoesbackground"
         Title="Promoções">
<ContentPage.Content>
    <ListView x:Name="listview_promocoes" Margin="0, 20, 0, 0 ">
            <ListView.ItemTemplate>
                <DataTemplate>
                <ViewCell>

                    <StackLayout BackgroundColor="AliceBlue" HorizontalOptions="Center" VerticalOptions="FillAndExpand">
                        <Label Text="{Binding titulo}" Style="{StaticResource labelsfont}"/>

                        <Image Source="{Binding imagem}" Aspect="AspectFill"/>
                    </StackLayout>


                </ViewCell>


            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>


</ContentPage.Content>

这是不好的结果(有 2 个项目 - 你看不到图像)

我想做这样的事情,但我不能使用边距,因为当我使用它时,应用程序无法运行。

它必须是 ListView 的一项。 所有项目都应该是这样的。

我该怎么做? 谢谢。

【问题讨论】:

    标签: xaml listview xamarin layout xamarin.forms


    【解决方案1】:

    您可以通过以下方式在 ListView 项目中获取该布局:

    <ListView
            RowHeight="170" 
            ItemsSource="{Binding Items}">
        <ListView.ItemTemplate>
            <DataTemplate>
            <ViewCell>
                <!-- Outter box containing two boxes -->
                <StackLayout 
                            VerticalOptions="FillAndExpand">
                    <!-- First box with Title, Image and Text -->
                    <StackLayout 
                                VerticalOptions="FillAndExpand" 
                                Padding="10, 5" 
                                BackgroundColor="Yellow">
                        <Label 
                                Text="YOUR_TITLE"
                                BackgroundColor="Silver"/>
                        <Image 
                                HorizontalOptions="FillAndExpand" 
                                BackgroundColor="Fuchsia" 
                                HeightRequest="60" />
                        <Label 
                                Text="YOUR_OTHER_TEXT"
                                BackgroundColor="Silver"/>
                    </StackLayout>
    
                    <!-- Second box with Text -->
                    <StackLayout 
                                VerticalOptions="End" 
                                Margin="0, 8, 0, 0" 
                                Padding="10, 5" 
                                BackgroundColor="Lime">
                        <Label 
                                Text="YOUR_TEXT_OTHER_BOX"
                                BackgroundColor="Silver"/>
                    </StackLayout>
                </StackLayout>
            </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
    

    我想你可能需要做一些小改动才能完全按照你的意愿得到它,但这已经很接近了。

    结果:

    希望这会有所帮助。-

    【讨论】:

    • 我使用了它,但我的图像又不大了……就像我在这里发布的照片​​一样。你在我的应用程序中只能看到一小部分图片:/ 我不知道发生了什么...
    • 似乎是一条线...在我的应用程序中似乎是一条线:/
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-16
    • 1970-01-01
    • 1970-01-01
    • 2012-02-15
    相关资源
    最近更新 更多