繁体   English   中英

在 Maui.net 上,为什么 Android 不会在键盘出现时自动将 ViewElement 滚动到视图中?

[英]On Maui.net, Why is Android is not automatically scroll ViewElement into view when keyboard appear?

在 .net-Maui 中,当我在 scrollView 中添加一个 ViewElement 并且键盘出现时,键盘隐藏了 ViewElement。 如果我删除 ScrollView 它工作正常,但我无法滚动内容。

在 Xamarin 上,Android 会自动将 ViewElement 滚动到视图中,那么为什么会发生这种变化?。

我必须在毛伊岛做些不同的事情吗?

这是代码示例。

 public class TestView : ContentView
    {
        public TestView()
        {
            var layout = new AbsoluteLayout();
            var scrollView = new ScrollView { Content = layout, };
            Content = scrollView;
            var entry = new Entry();
            layout.Add(entry);
            AbsoluteLayout.SetLayoutBounds(entry, new Rect(20, 600, 200, 45));
        }
    }

如果我这样做,它会起作用,但这对我来说不是解决方案。

 public class TestView : ContentView
    {
        public TestView()
        {
            var layout = new AbsoluteLayout();
            Content = layout ;
            var entry = new Entry();
            layout.Add(entry);
            AbsoluteLayout.SetLayoutBounds(entry, new Rect(20, 600, 200, 45));
        }
    }

我希望 ViewElement 自动滚动到视图中。

我得到了 Microsoft 的帮助来修复它。

答案在这里: https://learn.microsoft.com/en-us/answers/questions/1166483/why-is-android-is-not-automatically-scroll-viewele

来自 Microsoft:要解决此问题,您可以将以下代码添加到 MainActivity,这将解决问题:

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);
    Window.SetSoftInputMode(Android.Views.SoftInput.AdjustPan);
}
暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2023 STACKOOM.COM