Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Scrolling an image

(0) ShareShare
ReportReport
Posted on by 64

Hi all,


I have what might be a simple question on image scrolling, but I have tried a number of approaches and can't get it working the way I would like.

I have a screen with a resolution of 640x1136. On this screen I place an image of 1900x900. The idea is that the user can swipe on the screen to scroll across the image. What I have tried ...

- Use a horizontal gallery, setting the width of the gallery to >1900, and the item within the gallery of a similar width. Doesn't work. The part of the image which is currently visible on screen (the initial 640 pixels) is repeated as I scroll.  So the image appears corrupted. Scrolls beautifully though 🙂

If I limit the gallery to a single item (FirstN(gallery,1), i can see the full image in the power apps editor (not corrupted), but it doesn't scroll (even thought the item width is > 640).

Is it possible to have a horizontal gallery item width > screen width?

- Segment the image into smaller widths, and use a horizontal gallery, with each segmented part of the image placed in a separate item (of less than 640 pixels) within the gallery. Works, but alignment will be an issue as the final app has scale to fit enabled and the layout is slightly different on different devices as a result.

- Use an invisible slider control above the image, and tie the image X position to the slider value.  Works, but it has two drawbacks.

1.  Scroll is too fast, as I'm scrolling an image which is three times the width of the screen, using a slider control just under a single screen width

 

2. If the user touches the screen, they adjust the slider position and the image position 'jumps' as the image X position is tied to the slider value.

Ideally i want to measure the amount the slider has moved, and link that value to the Image X position, rather than the actual slider position.

I can set a variable to the initial slider value using the OnSelect property of the slider, then subtracting the current slider value from this initial value, I have the distance the slider moves. Great! But to support multiple swipes across the image, I need a running count of the total distance moved by the slider across multiple adjustments of the slider position, and this is where I am stuck.

I can use the OnChange property of the slider to update a variable with the total distance the slider has moved, but this only updates when the slider is released, but I need this variable updated as the slider is being moved.

 

Any ideas?

  • Amateure_ Profile Picture
    2 on at
    Re: Scrolling an image

    Hi
    are you able to share some screenshots of each step?
    That would be awesome.

    Thank you

    Cheers

  • Verified answer
    Jasondefaoite Profile Picture
    64 on at
    Re: Scrolling an image

    Ok, again for the benefit of anyone coming here in future. The best way to do this ... 

    Insert a vertical container. Set the horizontal Overflow property to Scroll. Set the width to the width of your image.

    Inside this container, insert a vertical gallery. Again, set the width as the width of your image. Set the number of items in the gallery to 1 by setting the items property to FirstN(CustomGallerySample,1).

    Inside the gallery insert your image, and set the width/height you need (width should match that of the gallery/container)

    Now, when using the phone, you can scroll across your image horizontally using standard swipe gestures and as this is in a gallery, you get rubber banding and 60Hz animations of the horizonal movement. 

    This is the solution I needed from the start 😉

  • Jasondefaoite Profile Picture
    64 on at
    Re: Scrolling an image

    Cheers. One correction, the minimum timer value appears to be 50ms. This equates to being able to update the image position 20 times a second, or 20Hz. Ideally it should be updating at 60Hz. But it works!

  • rubin_boer Profile Picture
    4,841 Super User 2024 Season 1 on at
    Re: Scrolling an image

    thats pretty cool 🙂

     
  • Jasondefaoite Profile Picture
    64 on at
    Re: Scrolling an image

    Thanks Rubin, upvoted.

    I managed to get it working. Solution for reference, I needed to add a timer.

     

    Slider onSelect sets initialPositionVariable = Slider.Value. It also sets variableStartTimer = true.
    Slider onChange sets the variableStartTimer = false.

    Add a timer with a duration of 10, with a start of varibleStartTimer and repeat of varibleStartTimer

     

    So far, when we select/touch the slider, the timer starts/repeats until we release the slider. Also with the initial selection of the slider, initialPositionVariable - Slider.Value = 0, and if we move the slider in either direction, initialPositionVariable - Slider.Value will give us the delta.

    Finally, we can set the timer's onTimerEnd to set myXvalue = myXvalue - (initialPositionVariable - Slider.Value)
    So myXvalue is updated every time the timer loops, adding the delta position to it. 

    Tie the image X position to myXvalue. 
    Make the slider the size of the screen, and the handle size ~ 600 and make all colors transparent.

    If you then swipe right to left on the screen, the image moves left to right.

  • rubin_boer Profile Picture
    4,841 Super User 2024 Season 1 on at
    Re: Scrolling an image

    it would be great. upvote the idea and it will def get a mention at the super user meeting A Control element that returns X and Y coordinates... - Power Platform Community (microsoft.com) 😉

  • Jasondefaoite Profile Picture
    64 on at
    Re: Scrolling an image

    First, thank you for taking the time to reply. I actually have tap to move the image already working. However I could see a number of initial users trying to swipe across the image to move it rather than tapping, given their experience with how most native iOS/Android apps work.

    I wanted to replace this tap to move with a swipe gesture.

  • rubin_boer Profile Picture
    4,841 Super User 2024 Season 1 on at
    Re: Scrolling an image

    hi @Jasondefaoite here is an idea, it does not give you precisely what you want but may get you in the right direction.

     

    set the image width to 1900 this will make the image go out of view. add two icons on the left and right of the screen and to scroll left set the left icon OnSelect to Set(_X,Image5.X-50) , right OnSelect = Set(_X,Image5.X+50) and two others  for up OnSelect = Set(_Y,Image5.Y-50) and down Set(_Y,Image5.Y + 50)  . On the image set the X to _X and the Y to _Y. now you can scroll the image. 

     

    Image "Zoomed"

    rubin_boer_0-1614947492512.png

     

    Select scrolling up

    rubin_boer_2-1614947599343.png

     

     

     

    Hope this helps

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,645 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,997 Most Valuable Professional

Leaderboard