The slider on android has a horizontal margin that is not present in iOS (I have xaml code below to show what i am talking about). Everything else seems to align properly and changing the margin, padding and horizontalOptions for the Slider (and StackLayout) doesn't fix this problem.
I am not that familiar with Xaml or Android's material design UI, so I may be missing something obvious. If not, is this the place where I need a custom renderer?
<StackLayout Padding="10" BackgroundColor="Gray">
<Button/>
<StackLayout Orientation="Horizontal">
<Slider HorizontalOptions="FillAndExpand"/>
<Button HorizontalOptions="End"/>
</StackLayout>
<Slider HorizontalOptions="FillAndExpand"/>
<Label Text="Ipsem"/>
</StackLayout>
@Demond , this is expected behaviour issue in Android
:
Remove the Padding
from Seekbar
if you don't need it:
public class MySliderRenderer : SliderRenderer
{
public MySliderRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Slider> e)
{
base.OnElementChanged(e);
Control.SetPadding(0, 0, 0, 0);
}
}
Answers
What's you mean "horizontal margin"? Could you please post a picture about it?
@YorkGo
I can't directly on this forum but here is the imgur link:
imgur.com/QhgC5qR
@Demond , this is expected behaviour issue in
Android
:Workaround
Remove the
Padding
fromSeekbar
if you don't need it:@YorkGo
Thank you! It worked like a charm.
For anyone else who might have the same problem and is unfamiliar with custom renderers, I recommend looking at the Creating Mobile Apps with Xamarin.Forms book (Chapter 26).