Plugin.SegmentedControl
Plugin.SegmentedControl copied to clipboard
Height property does not seem correct in Android
Hello, firstly thank you for your good work. When I implement your plugin to Android height property does not seem correct. If I add HeightRequest="30"
It seems good. Thank you in advance.
<sc:SegmentedControl
x:Name="xSegmentedControl"
Margin="10,0,10,10"
BackgroundColor="Blcak"
DisabledColor="Gray"
FontSize="16"
HeightRequest="30"
SegmentSelectedCommand="{Binding SegmentChangedCommand}"
SelectedSegment="{Binding SelectedSegment, Mode=TwoWay}"
SelectedTextColor="White"
TextColor="White"
TintColor="{Binding SegmentBackground}">
<sc:SegmentedControl.Children>
<sc:SegmentedControlOption Text="TAB 1" />
<sc:SegmentedControlOption Text="TAB 2" />
</sc:SegmentedControl.Children>
</sc:SegmentedControl>
Confirmed
XAML
<sc:SegmentedControl Grid.Column="1" BackgroundColor="LightGray" FontSize="12" HorizontalOptions="FillAndExpand" ItemsSource="{Binding MeasuresTypes}" SelectedSegment="{Binding MeasuresType, Mode=TwoWay}" SelectedTextColor="{StaticResource Material.Color.OnSecondary}" TextColor="{StaticResource Material.Color.OnBackground}" TintColor="{StaticResource Material.Color.Secondary}" VerticalOptions="FillAndExpand" />
Xamarin Forms: 4.5 Platform: ANDROID
Related to #69?
The reason the heightRequest="30"
makes it look correct is because this is a hard coded value here.
https://github.com/1iveowl/Plugin.SegmentedControl/blob/master/src/crossplatform/SegCtrl.Droid/Resources/layout/RadioButton.axml
Is there a way to get this to adjust automatically?
Thx @Hackmodford.
There probably is, but I don't currently know how. Feel free to look at it and create a PR.
I think I've solved this, but I'm not familiar with Android development, so there may be a better way.
In SegmentedControlRenderer.cs, modify the ConfigureRadioButton method to the following:
if (!(selectedShape is null))
{
selectedShape.SetStroke(borderWidthInPixel, borderColor);
selectedShape.SetColor(backgroundColor);
selectedShape.SetSize(0, ConvertDipToPixel(Element.HeightRequest));
}
if (!(unselectedShape is null))
{
unselectedShape.SetStroke(borderWidthInPixel, borderColor);
unselectedShape.SetColor(_unselectedItemBackgroundColor);
unselectedShape.SetSize(0, ConvertDipToPixel(Element.HeightRequest));
}
I need to do some more testing but I'll create a PR for this once I'm sure it's working. Seems strange that I can pass 0 as the value for the width to SetSize but it still works.
Confirmed. Anyone still working on this plugin?