我想将一个背景图片放在一个圆形的头像下面。我可以为此代码添加背景颜色,但我需要添加一些图像。那么我如何在我的代码中实现这个呢?
var avatarImage = new CircleImage
{
Aspect = Aspect.AspectFill,
WidthRequest = Device.OnPlatform(220, 220, 300),
HeightRequest = Device.OnPlatform(220, 220, 300),
Source = ImageSource.FromFile("about_background.png"),
};
avatarLayout.Children.Add(avatarImage);
此图片上的背景:example image
答案 0 :(得分:1)
像这样的东西?
public Page1()
{
InitializeComponent();
var stack = new StackLayout();
var grid = new Grid();
grid.HeightRequest = 400;
grid.BackgroundColor = Color.Red;
grid.RowDefinitions.Add(new RowDefinition());
grid.RowDefinitions.Add(new RowDefinition());
var bgrImg = new Image();
bgrImg.Aspect = Aspect.Fill;
bgrImg.Source = ImageSource.FromUri(new Uri("https://scontent-waw1-1.xx.fbcdn.net/v/t1.0-9/1609887_238338919678588_860551778_n.jpg?oh=469b60dbef099ca197f088f97e5e1436&oe=5852DA43"));
var img = new Image();
img.VerticalOptions = new LayoutOptions(LayoutAlignment.Center, false);
img.Source = ImageSource.FromUri(new Uri("https://scontent-waw1-1.xx.fbcdn.net/v/t1.0-9/1622680_238338033012010_860901821_n.jpg?oh=a216ba790ec4f771c7b9488fc819ed80&oe=5814192E"));
grid.Children.Add(bgrImg, 0, 0);
grid.Children.Add(img);
Grid.SetRowSpan(img, 2);
stack.Children.Add(grid);
Content = stack;
}
等待一段时间,直到加载背景图片。