首页 > 解决方案 > Xamarin.Forms.Entry 中的圆形边框不断被削减

问题描述

我的圆形边框条目被剪掉了。我的自定义渲染器中的代码使圆角的宽度大于我设置的边框宽度。如何删除角落上增加的边框宽度?

入口截图 代码:

var y = (float)CalculateResolutionScaling(25);
var x = new float[] { y, y, y, y, y, y, y, y };
var z = new RectF(35, 35, 35, 35);
var shape = new ShapeDrawable(new global::Android.Graphics.Drawables.Shapes.RoundRectShape(x, null, null));
shape.Paint.SetStyle(Paint.Style.Stroke);
shape.Paint.StrokeWidth = (float)CalculateResolutionScaling(control.BorderWidth * 2.75);
Control.Background = shape;
shape.Paint.Color = control.BorderColor.ToAndroid();

标签: c#xamarinxamarin.formsxamarin.android

解决方案


您所要做的就是将其添加到您的样式中:

圆角.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="10dp" />
<padding
    android:bottom="3dp"
    android:left="0dp"
    android:right="0dp"
    android:top="3dp" />
<gradient
    android:angle="90"
    android:endColor="@color/White"
    android:startColor="@color/White" />
<stroke
    android:width="1dp"
    android:color="@color/Gray" />
</shape>

然后像这样使用它:

 Control.Background = ResourcesCompat.GetDrawable(this.Resources, Resource.Style.RoundedCorner, null);

如果您想更改角的颜色,只需更改上面 XML 中的笔触颜色。

如果您有任何疑问,请随时回复。


推荐阅读