如何使 Xamarin.Forms.Editor 可滚动/自动调整大小?

Dpe*_*nha 3 xamarin.android xamarin.forms

我有一个带有编辑器的滚动布局,我想让它可以滚动或自动调整大小以适应内容。

我找不到怎么做。

我尝试了自定义渲染器,但找不到如何将 InputMethods 设置为 Control。

有任何想法吗?

Dpe*_*nha 5

在这篇文章的帮助下:https : //forums.xamarin.com/discussion/80360/editor-inside-scrollview-not-scrolling

这修复了 Android 上的滚动(iOS 默认工作)。它在触摸编辑器内部时避免了父滚动事件,仅触发编辑器滚动。

首先是关于Android项目的课程:

using Android.Views;
namespace MyApp.Droid
{
    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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在 Android 自定义 EditorRenderer 上使用它:

protected override void OnElementChanged(ElementChangedEventArgs<Editor> 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();
    }
}
Run Code Online (Sandbox Code Playgroud)