2017-08-10 109 views
0

我试图更改Xamarin Forms应用程序中Android复选框的大小。首先是一些背景。我安装在Xamarin形式的,看起来复选框的自定义控制,如:更改Xamarin Android复选框的大小

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

    // Other properties... 
} 

在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... 
     } 
    } 
} 

我然后使用复选框页上如此:

<StackLayout Orientation="Horizontal" BackgroundColor="White" Padding="5" Margin="0" HorizontalOptions="FillAndExpand"> 
    <controls:CheckBox HorizontalOptions="Start" WidthRequest="25" HeightRequest="25" /> 

如果我使宽度和高度更小,然后25复选框将被剪裁。

Clipped CheckBox

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

enter image description here

我试图调整大小的东西,如在本机控制,也是布局参数的大小相同。没有工作。

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

var lp = _nativeControls.LayoutParameters; 
lp.Width = 35; 
lp.Height = 35; 
_nativeControls.LayoutParameters = lp; 

有什么我可以尝试的其他建议吗?谢谢。

回答

0

尝试使用规模:

var checkbox = new CheckBox(Context); 
checkbox.ScaleX = 1.5f; 
checkbox.ScaleY = 1.5f; 
+0

谢谢你的回答史蒂夫。我应该提到我曾尝试过ScaleX/Y,并且它可以工作。我希望有一种方法来设置复选框的特定大小。谢谢。 –

+0

我找不到更好的答案,然后Steve提供了如此标记他的答案为接受。谢谢史蒂夫。 –