4

我想做的是:

我的视图中有一个滚动视图,它的高度就像父高度的 2/9。然后用户可以翻译这个滚动视图以使其更大。然而滚动视图的大小并没有明显改变。因此,即使它更大,滚动视图的大小也保持不变,这很重要。一开始我可以把它变大。但是它不会滚动,因为它的大小足够大而不能滚动。

不知道能不能解释清楚。希望我做到了。

问候。

编辑 - - - - - - -

一些代码可以进一步解释我的观点

这是滚动视图

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
            };

I put the scrollview inside a contentview otherwise Its scroll indexes becomes 0 when they are translated. Ref: Xamarin Forms: ScrollView returns to begging on TranslateTo

4

1 回答 1

3

The problem was, translateTo only changes the position of the element. I could use scaleTo after the translation. However it changes the both dimensions. Someone from Xamarin Forums suggested me to use LayoutTo which I did not know existed. With layoutTo you can change both the size and location. Giving an instance of Rectangle type.

于 2015-12-08T00:39:19.667 回答