dailiboy 2023-12-13 00:23 采纳率: 12.5%
浏览 22
已结题

Xamarin.Forms图片不显示

Xamarin.Forms项目。
我编写了一个页面,其中插入了图片。图片占位了,但是没有显示出来。请问这个问题怎么解决。


<?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:local="clr-namespace:ESP8266APP"
             x:Class="ESP8266APP.MainPage">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Label Text="登录" FontSize="Large" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
        <Label Text="注册" FontSize="Large" VerticalOptions="CenterAndExpand" TextColor="Blue" HorizontalOptions="End" Margin="0,0,20,0">
            <Label.GestureRecognizers>
                <TapGestureRecognizer Tapped="OnLoginLabelTapped"/>
            </Label.GestureRecognizers>
        </Label>
        <Image Source="images/logo.jpg" Aspect="AspectFit" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" WidthRequest="800" HeightRequest="480" />
        <Entry Grid.Row="2" Placeholder="用户名" Margin="20" />
        <Entry Grid.Row="3" Placeholder="密码" Margin="20" IsPassword="True" />

        <Button Grid.Row="4" Text="登录" Command="{Binding LoginCommand}" HorizontalOptions="FillAndExpand" Margin="20"/>
    </Grid>

</ContentPage>

img

img

img


第一次做这种页面,可能这个问题对于大家来说太简单了。还请指点

  • 写回答

11条回答 默认 最新

  • dailiboy 2023-12-14 21:34
    关注

    该问题我已通过ChatGPT解决。
    将图片放到安卓项目下的Resources/drawable目录下,右击图片属性,将 生成操作 更改为 AndroidResource。引用图片的时候路径是“drawable/logo.jpeg”,应该是以Resources这个文件夹作为根目录的。
    感谢楼上的朋友,虽然没有解决问题,但是给了一定的思路。

    评论

报告相同问题?

问题事件

  • 系统已结题 12月22日
  • 赞助了问题酬金15元 12月14日
  • 创建了问题 12月13日