Ihor Levkivskyi
Ihor Levkivskyi

Reputation: 391

Cannot display two scrollview together in stacklayout in Xamarin Forms

I try to add two horizontal scrollviews together in one stacklayout. But displayed only last scrollview(scrollView1). Why first scrollView doesn't display?

var avatarLayout = new StackLayout()
            {
               HeightRequest = 500,
            };

StackLayout st = new StackLayout()
                {
                    Orientation = StackOrientation.Horizontal
                };
                st.Children.Add(postImage1);
                st.Children.Add(postImage2);
                st.Children.Add(postImage3);

StackLayout st1 = new StackLayout()
                {
                    Orientation = StackOrientation.Horizontal
                };
                st1.Children.Add(postImage4);
                st1.Children.Add(postImage5);
                st1.Children.Add(postImage6);

                ScrollView scrollView = new ScrollView()
                    {
                    HorizontalOptions = LayoutOptions.Fill,
                    Orientation = ScrollOrientation.Horizontal,
                    Content = new StackLayout{
                        Orientation = StackOrientation.Horizontal,
                        Children = {st}
                    }
                };

                ScrollView scrollView1 = new ScrollView()
                {
                    HorizontalOptions = LayoutOptions.Fill,
                    Orientation = ScrollOrientation.Horizontal,
                    Content = new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal,
                        Children = {st1}
                    }
                };
                avatarLayout.Children.Add(avatarImage);
                avatarLayout.Children.Add(friends);
                avatarLayout.Children.Add(scrollView);
                avatarLayout.Children.Add(cars);
                avatarLayout.Children.Add(scrollView1);
                avatarLayout.Children.Add(posts1);

Solved.

Upvotes: 0

Views: 187

Answers (1)

DavidS
DavidS

Reputation: 2934

The code above isn't adding any children to st1, so scrollView1 don't have anything to display. It looks like the code ought to be displaying scrollView (not scrollView1), but with the content that was intended for both ScrollView containers. I suspect the calls after the creation of st1 should be st1.Children.Add(...) not st.Children.Add(...).

Upvotes: 1

Related Questions