Goal
I am trying to allow a scrollview
to overflow (not clip its children). I have this working with a carousel view but cannot get the same result with a scrollview
. I have it working on iOS but not Android (this is about android).
The idea of this is to center the scrollview
and allow overflow so the content can look centered (being used as tabs).
Code
Use of the scrollview
in Xamarin Forms:
var scrollView = new ScrollView
{
WidthRequest = 200,
HorizontalOptions = LayoutOptions.Center,
Orientation = ScrollOrientation.Horizontal,
Content = scrollViewContent,
IsClippedToBounds = false
};
This is my custom renderer for the scrollview
(Android):
public class CenteredScrollViewRenderer : ScrollViewRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.OldElement != null || this.Element == null)
return;
if (e.OldElement != null)
e.OldElement.PropertyChanged -= OnElementPropertyChanged;
e.NewElement.PropertyChanged += OnElementPropertyChanged;
}
protected void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (ChildCount > 0)
{
GetChildAt(0).HorizontalScrollBarEnabled = false;
GetChildAt(0).VerticalScrollBarEnabled = false;
GetChildAt(0).OverScrollMode = OverScrollMode.Never;
// Try and disable clip
((ViewGroup)GetChildAt(0)).SetClipToPadding(false);
((ViewGroup)GetChildAt(0)).SetClipChildren(false);
}
}
}
Other attempts
I have also created a function to go through ALL parents to disable clipping just to see if it was a parent causing a problem. This still has not worked.
So how to we allow the scrollview
content to overflow outside of its bounds?
Note: This is on stackoverflow too: https://stackoverflow.com/questions/47013871/scrollview-allow-content-overflow