Maui android change scrolling to neither not working

Haviv Elbsz 2,091 Reputation points
2024-02-07T19:57:40.6466667+00:00

Hello all. Maui 17.9 preview 5 and android 34. I tried to change scrolling to neither and this no work. myscroll.orientation = scrollorientation.neither but this not working. Please any help in this Thank you very much.

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2024-02-08T02:43:38.6233333+00:00

    Hello,

    This is a known issue in github [Android] ScrollView Orientation=Neither not working #18418.

    For this problem, you can use Android's native method to disable or enable scrolling in ScrollView. Please refer to the following steps.

    Step 1. Create a touch listener for ScrollView under the Android folder.

    internal class MyTouchListener : Java.Lang.Object, IOnTouchListener
    {
        public AndroidX.Core.Widget.NestedScrollView NestedScroView { get; set; }
        public bool ScrollEnabled { get; set; }
        public MyTouchListener(bool enabled, NestedScrollView view)
        {
            NestedScroView = view;
            ScrollEnabled = enabled;
        }
        public bool OnTouch(global::Android.Views.View? v, MotionEvent? e)
        {
            if (ScrollEnabled==true)
            {
                return NestedScroView.OnTouchEvent(e);
            }
            else
            {
                return true; // If it returns true directly, ScrollView deactivates scrolling behavior.
            }
           
        }
    }
    

    Step 2. Disable or enable scrolling via the handler settings.

    <ScrollView x:Name="scroll">
    // disable scrolling
                scroll.HandlerChanged += (sender, e) =>
                {
    #if ANDROID
                    var s = scroll.Handler.PlatformView as AndroidX.Core.Widget.NestedScrollView;
                    if (s != null)
                    {
                        s.SetOnTouchListener(new MyTouchListener(false,s));
                    }
    #endif
                };
    // enable scrolling
    #if ANDROID
                var s = scroll.Handler.PlatformView as AndroidX.Core.Widget.NestedScrollView;
                if (s != null)
                {
                    s.SetOnTouchListener(new MyTouchListener(true, s));
                }
    #endif
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our [documentation][1] to enable e-mail notifications if you want to receive the related email notification for this thread. [1]: https://docs.microsoft.com/en-us/answers/articles/67444/email-notifications.html

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.