我在Xamarin中使用自定义渲染实现了单选按钮。单选按钮向左对齐,文本默认对齐。我们如何才能将单选按钮的位置改为右侧?
Xaml Code低于
<StackLayout HorizontalOptions="Start" VerticalOptions="CenterAndExpand">
<control:BindableRadioGroup x:Name="SortPicker"
TextColor="Gray"
CheckedChanged="OnCheckedChanged"
Padding="50,0,0,10"
WidthRequest="1100"
Spacing="20">
</control:BindableRadioGroup>
</StackLayout>
呈现代码:
protected override void OnElementChanged(ElementChangedEventArgs<CustomRadioButton> e)
{
base.OnElementChanged(e);
if (Control == null)
{
var radButton = new RadioButton(Context);
colorStateList = radButton.TextColors;
radButton.CheckedChange += this.RadButtonCheckedChange;
SetNativeControl(radButton);
}
Control?.SetPadding(30, Control.PaddingTop, 0, Control.PaddingBottom);
Control.Text = e.NewElement.Text;
Control.Checked = e.NewElement.Checked;
UpdateTextColor();
if (e.NewElement.FontSize > 0)
{
Control.TextSize = (float)e.NewElement.FontSize;
}
if (!string.IsNullOrEmpty(e.NewElement.FontName))
{
Control.Typeface = TrySetFont(e.NewElement.FontName);
}
}
答案 0 :(得分:0)
尝试在应用程序清单中启用supportsRtl属性为true:
<application android:label="app label" android:supportsRtl="true"/>
并设置Control的LayoutDirectionProperty如下:
Control.LayoutDirection = LayoutDirection.Rtl;