xamarin - Xamarin 表单上带有绿色边框的多个圆形图像作为地图引脚,Xamarin android Xamarin IOS
问题描述
我有一个应该有圆形边框的图像。请帮助我从现在开始挣扎
解决方案
解决方案1:
您可以将图像放在Frame中,并设置CornerRadius和BorderColor。
<Frame CornerRadius="50" Padding="0" BorderColor="Green" HeightRequest="100" WidthRequest="100">
<Image Source="xxx.png" />
</Frame>
解决方案2:
您可以 Custom Renderer
在 xamarin.forms中使用
在 iOS 中
//...
using xxx;
using xxx.iOS;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(MyImage), typeof(MyImageRenderer))]
namespace xxx.iOS
{
public class MyImageRenderer:ImageRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Image> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.Layer.MasksToBounds = true;
Control.Layer.CornerRadius = 50; //set the rounded corner
Control.Layer.BorderColor = UIColor.Green.CGColor;
Control.Layer.BorderWidth = 1;
}
}
}
}
在安卓中
在文件夹Resource->drawable中创建一个 xml 文件 image_view_style.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle">
<solid
android:color="#00ff00" />
<corners
android:radius="50dp" />
<stroke
android:width="1dp"
android:color="#00ff00" />
</shape>
</item>
using Android.Support.V4.Content.Res;
using xxx;
using xxx.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(MyImage), typeof(MyImageRenderer))]
namespace xxx.Droid
{
public class MyImageRenderer:ImageRenderer
{
public MyAndriodEntry(Context context):base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Image> e)
{
base.OnElementChanged(e);
if(Control!=null)
{
Control.SetBackgroundResource(Resource.Drawable.image_view_style);
}
}
}
}
在表格中
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
namespace xxx
{
public class MyImage : Image
{
public MyImage()
{
}
}
}
推荐阅读
- android - 按钮颜色和渐变的功能
- perl - 无法在 perl 中获取 YAML 文档节点
- awk - awk zip 行,如 python zip
- android - 毕加索没有在 ImageView 上加载图像
- python - 加载模型和应用预测的正确方法
- java - 使用 if else 语句进行 JOptionPane 输入验证
- php - Query Join table to sort by menudindex
- java - eclipselink的级联删除问题
- ruby-on-rails - Webpacker 安装给出错误:无法加载此类文件 — ubygems
- java - GCloud java错误:java.lang.IllegalStateException:响应已经提交