我尝试在一个stacklayout中添加两个水平滚动视图 . 但只显示最后一个scrollview( scrollView1
) . 为什么首先 scrollView
不显示?
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.
1 回答
上面的代码没有向st1添加任何子代,因此scrollView1没有任何要显示的内容 . 看起来代码应该显示scrollView(而不是scrollView1),但是内容适用于两个ScrollView容器 . 我怀疑创建st1后的调用应该是st1.Children.Add(...)而不是st.Children.Add(...) .