1iveowl / Plugin.SegmentedControl

MIT License
170 stars 29 forks source link

Height property does not seem correct in Android #81

Open kerberosargos opened 4 years ago

kerberosargos commented 4 years ago

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.

Screenshot

  <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>
fgbustoa commented 4 years ago

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" />

Annotazione 2020-03-19 101548

Xamarin Forms: 4.5 Platform: ANDROID

1iveowl commented 4 years ago

Related to #69?

Hackmodford commented 4 years ago

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?

1iveowl commented 4 years ago

Thx @Hackmodford.

There probably is, but I don't currently know how. Feel free to look at it and create a PR.

grantjames commented 3 years ago

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.

thomasgalliker commented 10 months ago

Confirmed. Anyone still working on this plugin?