question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ScrollView scrollToVerticalOffset don't work on Android

See original GitHub issue

I want to include a scrollToId() method in my ts.

fiche.html :

<ScrollView id="myScroller">
       <FlexboxLayout (tap)="scrollToId('google-map')">
           .....
       </FlexboxLayout>
       <FlexboxLayout (tap)="scrollToId('horaire')">
            ....
       </FlexboxLayout>
       <StackLayout id="horaire">
          ....
       </StackLayout>
       <GridLayout id="google-map">
            ...
        </GridLayout>
</ScrollView>

fiche.ts :

public scrollToId(id: string) {
        if (this.scrollLayout == null) {
            this.scrollLayout = this.page.getViewById("myScroller");
        }

        let focus = this.page.getViewById(id);

        this.scrollLayout.scrollToVerticalOffset(focus.verticalOffset, false);
    }

All is ok on IOS but on Android, no scroll to StackLayout or GridLayout.

Any help on this?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
NickIlievcommented, Jan 11, 2017

@Neferteus neither StackLayout nor GridKLayout have verticalOffset property. However you can use methods like getLocationRelativeTo or getLocationOnScreen / getLocationOnWindow or even getMeasuredHeight to calculate and scroll to the desired position.

e.g. page.component.html

<ScrollView #myScroller>
    <StackLayout>
        <Button #btn text="scrollTo" (tap)="scrollTo()"></Button>

        <StackLayout>
            <Image src="res://logo"></Image>
            <Image src="res://icon"></Image>
            <Image src="res://logo"></Image>
            <Image src="res://icon"></Image>
        </StackLayout>

        <GridLayout #grid width="200" height="200" backgroundColor="green">
            
        </GridLayout>
    </StackLayout>
</ScrollView>

page.component.ts

export class AppComponent implements OnInit {

    @ViewChild("myScroller") sv: ElementRef;
    @ViewChild("btn") btn: ElementRef;
    @ViewChild("grid") gr: ElementRef;

    scrollLayout: ScrollView;
    button: Button;
    grid: GridLayout;

    ngOnInit() {
        this.scrollLayout = this.sv.nativeElement;
        this.button = this.btn.nativeElement; 

        this.grid = this.gr.nativeElement;
    }

    public scrollTo() {
        this.scrollLayout.scrollToVerticalOffset(this.grid.getLocationRelativeTo(this.button).y, false);   
    }
}
1reaction
vishwa1937commented, Dec 26, 2018

Thank you @mster 😃 . I will try as you said and let you know about it. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ScrollToVerticalOffset() doesn't work? - Stack Overflow
Mine is started work after; ScrollViewer.UpdateLayout(); ScrollViewer.ScrollToVerticalOffset(outPoint.Y);.
Read more >
ScrollViewer ScrollToVerticalOffset not working properly with ...
Hello,. I'm having troubles trying to dynamically scroll down TextControls (TextBox, TextBlock, RichTextBox) accordingly to their content.
Read more >
WPF scrollviewer with Inertia - CodeProject
You can use ScrollViewer.ScrollToVerticalOffset to control the vertical scrolling of the ScrollViewer , as well as horizontally.
Read more >
ScrollView - Android Developers
The scrollbar style to display the scrollbars at the edge of the view, increasing the ... insets that don't change when system bars...
Read more >
[Solved]-scroll viewer text block scrolling in WP7-C#
In the code-behind, I added a DependencyProperty (which we can animate from outside) that calls the ScrollToVerticalOffset() method of our ScrollViewer at ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found