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複選框將被剪裁。
如果我做的寬度和高度不大於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;
有什麼我可以嘗試的其他建議嗎?謝謝。
謝謝你的回答史蒂夫。我應該提到我曾嘗試過ScaleX/Y,並且它可以工作。我希望有一種方法來設置複選框的特定大小。謝謝。 –
我找不到更好的答案,然後Steve提供瞭如此標記他的答案爲接受。謝謝史蒂夫。 –