Horizontal ScrollView - xamarin.forms

和自甴很熟 提交于 2020-01-04 03:57:05

问题


I know there are many about this topic (Scroll horizontally in Xamarin.Forms ScrollView), but I could not implement the horizontal scrollview which scrolls horizontally.

public class DetailView : ContentPage
{
    public DetailView ()
    {
        StackLayout stack = new StackLayout {
            Orientation = StackOrientation.Horizontal,
            };
        for (int i = 0; i < 40; i++)
            stack.Children.Add (new Button { Text = "Button" });
        var scrollView = new ScrollView
        {
            Orientation = ScrollOrientation.Horizontal,
            Content = stack
        };
        Content = scrollView;
    }   
}

Any ideas?


回答1:


try this:

public DetailView()
{
    var scrollableContent = new StackLayout()
    {
        Orientation = StackOrientation.Horizontal,
        HorizontalOptions = LayoutOptions.Fill,
        Children =
        {
            new BoxView(){HeightRequest=40, WidthRequest=40, BackgroundColor = Color.Red},
            new BoxView(){HeightRequest=40, WidthRequest=40, BackgroundColor = Color.Green},
            new BoxView(){HeightRequest=40, WidthRequest=40, BackgroundColor = Color.Blue},
            new BoxView(){HeightRequest=40, WidthRequest=40, BackgroundColor = Color.Maroon},
        }
    };

    Content = new ScrollView()
    {
        HorizontalOptions = LayoutOptions.FillAndExpand,
        Orientation = ScrollOrientation.Horizontal,
        Content = scrollableContent,
    };
}


来源:https://stackoverflow.com/questions/28580153/horizontal-scrollview-xamarin-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!