Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
138 views
in Technique[技术] by (71.8m points)

c# - How to resize ScrollView when scaling inner AbsoluteLayout?

Working with Xamarin.Forms 5.0, all platforms (iOS, Android and UWP).

Inside a ScrollView, I've put an AbsoluteLayout with an image. When I scale the AbsoluteLayout the ScrollView doesn't resize according to the new size of the AbsoluteLayout/image. As a result, when zooming in image gets "cropped" and when zooming out a lot of "empty margins" appear.

I've done a simple example showing this case in the simplest possible way:

MainPage.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="ImageZoomExample.MainPage">
    <StackLayout>
        <ScrollView Orientation="Both">
            <AbsoluteLayout x:Name="AbsLayoutCtrl">
                <Image Source="https://upload.wikimedia.org/wikipedia/commons/d/dc/Grumpy_Cat_%2814556024763%29_%28cropped%29.jpg" />
            </AbsoluteLayout>
        </ScrollView>
        <Slider x:Name="SliderCtrl" HorizontalOptions="Fill" Minimum="-4" Value="0" Maximum="5" ValueChanged="SliderCtrl_ValueChanged" />
    </StackLayout>
</ContentPage>

MainPage.xaml.cs:

using Xamarin.Forms;

namespace ImageZoomExample
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
        }
        private void SliderCtrl_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            double scale;
            if (e.NewValue < 0)
            {
                scale = 1 / (1 - e.NewValue);
            }
            else
            {
                scale = 1 + e.NewValue;
            }
            AbsLayoutCtrl.Scale = scale;
        }
    }
}

How can I resize properly the ScrollView when zooming in/out?

question from:https://stackoverflow.com/questions/65865521/how-to-resize-scrollview-when-scaling-inner-absolutelayout

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...