我想做的是:
我的 View 中有一个 ScrollView ,它的高度就像父高度的 2/9。然后用户可以翻译此 ScrollView 以使其更大。但是 ScrollView 的大小并没有明显变化。因此,即使 ScrollView 更大,它的大小也保持不变,这就是重点。我一开始可以让它变大。但是它不会滚动,因为尺寸大到无法滚动。
不知道能不能解释清楚。希望我做到了。
问候。
编辑
-------------
一些代码来进一步解释我的观点
这是 ScrollView
public class TranslatableScrollView : ScrollView
{
public Action TranslateUp { get; set; }
public Action TranslateDown { get; set; }
bool SwipedUp;
public TranslatableScrollView()
{
SwipedUp = false;
Scrolled += async delegate {
if (!SwipedUp && ScrollY > 0) {
TranslateUp.Invoke ();
SwipedUp = true;
} else if (SwipedUp && ScrollY <= 0) {
TranslateDown.Invoke ();
SwipedUp = false;
}
};
}
}
这是页面中的代码
sv_footer = new TranslatableScrollView {
Content = new StackLayout {
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
Children = {
l_details,
l_place
},
}
};
sv_footer.TranslateUp += new Action (async delegate {
Parent.ForceLayout();
await cv_scrollContainer.TranslateTo(0, -transX, aSpeed, easing);
});
sv_footer.TranslateDown += new Action (async delegate {
await cv_scrollContainer.TranslateTo(0, 0, aSpeed, easing);
});
cv_scrollContainer = new ContentView {
Content = sv_footer,
VerticalOptions = LayoutOptions.Fill
};
我将 ScrollView 放在内容 View 中,否则在翻译时其滚动索引变为 0。引用:Xamarin Forms: ScrollView returns to begging on TranslateTo
最佳答案
问题是, translateTo 只改变元素的位置。我可以在翻译后使用 scaleTo。然而,它改变了两个维度。 Xamarin 论坛的某个人建议我使用我不知道存在的 LayoutTo。使用 layoutTo 您可以更改大小和位置。给出一个 Rectangle 类型的实例。
关于Xamarin 表单 : Change the size of scrollview on translateto,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34083602/