更改 Xamarin Android 复选框的大小

Chr*_*s C 1 xamarin.android android-checkbox

我正在尝试更改 Xamarin Forms 应用程序中 Android 复选框的大小。首先介绍一下背景。我在 Xamarin Forms 中为复选框设置了一个自定义控件,如下所示:

public class CheckBox : View
{
    public static readonly BindableProperty IsCheckedProperty =
        BindableProperty.Create(nameof(IsChecked), typeof(bool), typeof(CheckBox), false, propertyChanged: IsCheckedChanged);

    // Other properties...
}
Run Code Online (Sandbox Code Playgroud)

在 Android 项目中,我的渲染器如下所示:

[assembly: ExportRenderer(typeof(CheckBox), typeof(CheckBoxRenderer))]
namespace SmallVictories.Droid.Controls
{

    internal class CheckBoxRenderer : ViewRenderer<CheckBox, Android.Widget.CheckBox>
    {
        protected override void OnElementChanged(ElementChangedEventArgs<CheckBox> e)
        {
            if (Control == null)
            {
                _nativeControl = new Android.Widget.CheckBox(Context);
                SetNativeControl(_nativeControl);
            }

            // Other setup...
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我使用页面上的复选框,如下所示:

<StackLayout Orientation="Horizontal" BackgroundColor="White" Padding="5" Margin="0" HorizontalOptions="FillAndExpand">
    <controls:CheckBox HorizontalOptions="Start" WidthRequest="25" HeightRequest="25" />
Run Code Online (Sandbox Code Playgroud)

如果我将宽度和高度设置为小于 25,则复选框将被剪切。

裁剪的复选框

如果我将宽度和高度设置为大于 25,则复选框保持相同的大小,但可点击区域会变大。下面是复选框大小设置为 35,但它的大小与设置为 25 时的大小相同。

在此处输入图片说明

我尝试调整诸如本机控件的大小以及布局参数之类的内容。没用。

// Neither of these work.
_nativeControl.SetWidth(35);
_nativeControl.SetHeight(35);

var lp = _nativeControls.LayoutParameters;
lp.Width = 35;
lp.Height = 35;
_nativeControls.LayoutParameters = lp;
Run Code Online (Sandbox Code Playgroud)

关于我可以尝试的任何其他建议?谢谢。

Ste*_*rne 5

尝试使用规模:

var checkbox = new CheckBox(Context);
checkbox.ScaleX = 1.5f;
checkbox.ScaleY = 1.5f;
Run Code Online (Sandbox Code Playgroud)