Editor inside Scrollview not scrolling.

I have an editor control inside a StackLayout which is inside a ScrollView. I can scroll all the controls but when I go into an editor control if the text superpasses the editor's height I cannot scroll into the previously added text. So if the line goes out of the visible part of the editor I cannot go back to it, the only way is to erase the whole text and write something up again. So basically trying to scroll inside the editor results in scrolling out the controls inside the scrollview but I just want to scroll inside the editor. By the way editors are added to the stacklayout dynamically.

<ScrollView>
                <StackLayout x:Name="content" Orientation="Vertical"></StackLayout>
            </ScrollView>

Any suggestions?

Thank you.

Answers

  • MarcoMacedoMarcoMacedo BRMember

    DId you found any solution?

  • KaranPatelKaranPatel USMember

    Hi found any solution to this problem

  • KaranPatelKaranPatel USMember

    Hi found any solution to this problem

  • DurgaPrasadMailapalliDurgaPrasadMailapalli BYUniversity ✭✭
    edited January 27

    Hi,
    I found solution for this problem, it is working for me.

    1. Write a listener
      public class DroidTouchListener : Java.Lang.Object, View.IOnTouchListener
      {
      public bool OnTouch(View v, MotionEvent e)
      {
      v.Parent?.RequestDisallowInterceptTouchEvent(true);
      if ((e.Action & MotionEventActions.Up) != 0 && (e.ActionMasked & MotionEventActions.Up) != 0)
      {
      v.Parent?.RequestDisallowInterceptTouchEvent(false);
      }
      return false;
      }
      }

    2. Write custom renderer
      public class CustomEditorRenderer : EditorRenderer
      {
      protected override void OnElementChanged(ElementChangedEventArgs e)
      {
      base.OnElementChanged(e);
      if (e.OldElement == null)
      {
      var nativeEditText = (global::Android.Widget.EditText)Control;

                  //While scrolling inside Editor stop scrolling parent view.
                  nativeEditText.OverScrollMode = OverScrollMode.Always;
                  nativeEditText.ScrollBarStyle = ScrollbarStyles.InsideInset;
                  nativeEditText.SetOnTouchListener(new DroidTouchListener());
      
                  //For Scrolling in Editor innner area
                  Control.VerticalScrollBarEnabled = true;
                  Control.MovementMethod = ScrollingMovementMethod.Instance;
                  Control.ScrollBarStyle = Android.Views.ScrollbarStyles.InsideInset;
                  //Force scrollbars to be displayed
                  Android.Content.Res.TypedArray a = Control.Context.Theme.ObtainStyledAttributes(new int[0]);
                  InitializeScrollbars(a);
                  a.Recycle();
              }
          }
      }
      
  • RobinHosRobinHos NLMember

    Thanks @DurgaPrasadMailapalli this worked for me.

  • Oliv3rOliv3r USMember ✭✭

    @DurgaPrasadMailapalli @RobinHos Where do you put the droidListener? And do you have a similar solution to iOS?

  • DurgaPrasadMailapalliDurgaPrasadMailapalli BYUniversity ✭✭

    Hi,
    1. Where do you put the droidListener?
    You can put anywhere in the hierarchy of android solution, and call from custom renderer by this following code nativeEditText.SetOnTouchListener(new DroidTouchListener());

    1. do you have a similar solution to iOS?
      not required for iOS it will scroll individually.
  • dpedrinhadpedrinha DEMember ✭✭✭

    @DurgaPrasadMailapalli that worked great! Thsnk you.

    So sad that Xamarin forms miss such basic behaviors.

Sign In or Register to comment.