Plugin.SegmentedControl icon indicating copy to clipboard operation
Plugin.SegmentedControl copied to clipboard

Height property does not seem correct in Android

Open kerberosargos opened this issue 4 years ago • 6 comments

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>

kerberosargos avatar Mar 12 '20 06:03 kerberosargos

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

fgbustoa avatar Mar 19 '20 09:03 fgbustoa

Related to #69?

1iveowl avatar Apr 06 '20 09:04 1iveowl

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?

Hackmodford avatar Apr 06 '20 21:04 Hackmodford

Thx @Hackmodford.

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

1iveowl avatar Apr 07 '20 21:04 1iveowl

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.

grantjames avatar Apr 14 '21 14:04 grantjames

Confirmed. Anyone still working on this plugin?

thomasgalliker avatar Jan 25 '24 13:01 thomasgalliker