c# - 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();
解决方案
您所要做的就是将其添加到您的样式中:
圆角.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 中的笔触颜色。
如果您有任何疑问,请随时回复。
推荐阅读
- eslint - ESLint:如何在 VSCode 折叠区域注释上间隔注释异常
- node.js - Angular / Electron 服务输出传递给变量但返回未定义
- ruby-on-rails-4 - rails 强制在 where 子句中执行 SQL 查询
- slurm - 普通用户和 sacctmgr 为某个帐户创建的用户有什么区别?
- blueprism - 可以在未安装 Blue Prism 的机器上部署 Blue Prism 解决方案吗?
- postgresql - Pyspark:使用 JDBC 将数据写入 Postgres
- reactjs - 无法在 netlify 上部署应用,可以离线构建
- google-apps-script - 重命名和移动团队云端硬盘中的文件
- javascript - 未捕获的引用错误:
未在 HTMLInputElement.onclick ((index):15) 中定义 - python - SQLAlchemy 计数子查询结果