You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET MAUI 10:键盘显示时无法滚动到ScrollView底部

Android端.NET MAUI 10滚动异常问题求助

异常场景

  • 场景1:选择Editor → 向上滚动 → 输入文本 → UI跳转至Editor → 可滚动到ScrollView底部
  • 场景2:选择Editor → 直接输入文本 → 无法滚动到ScrollView底部
  • 补充异常:无法滚动到底部,且滚动可达范围取决于输入文本时ScrollView的位置

已尝试的解决操作

  • 在MainActivity.cs中配置WindowSoftInputMode = SoftInput.AdjustResize
  • 给ContentPage添加SafeAreaEdges="All"属性

测试代码

MainActivity.cs

[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ScreenOrientation = ScreenOrientation.Portrait, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density, WindowSoftInputMode = SoftInput.AdjustResize)]
public class MainActivity : MauiAppCompatActivity
{
}

ViewModel

public partial class vm_Overview : ObservableObject
{
    public vm_Overview()
    {
        myList.Add("AAA");
        myList.Add("BBB");
        myList.Add("CCC");
    }

    [ObservableProperty]
    private ObservableCollection<string> myList = new();
}

View

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             ...
             xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             x:DataType="vm:vm_Overview"
             Title="Overview">
    
    <ScrollView>
        <VerticalStackLayout Padding="10" Spacing="15">
            <Grid MinimumHeightRequest="500">
                <Button Text="Test 1"/>
            </Grid>

            <Label Text="Label 1" />

            <VerticalStackLayout BindableLayout.ItemsSource="{Binding MyList}" Spacing="5">
                <BindableLayout.ItemTemplate>
                    <DataTemplate>
                        <VerticalStackLayout x:DataType="x:String">
                            <Entry Text="{Binding .}"/>
                        </VerticalStackLayout>
                    </DataTemplate>
                </BindableLayout.ItemTemplate>

                <BindableLayout.EmptyView>
                    <Label Text="Empty..." MinimumHeightRequest="15" Margin="0,-5,0,0"/>
                </BindableLayout.EmptyView>
            </VerticalStackLayout>

            <Grid ColumnDefinitions="*,10,*">
                <Button Text="Test 2" Grid.Column="0"/>
            </Grid>

            <Button Text="Test 3" MinimumHeightRequest="500"/>

            <Label Text="END"/>
        </VerticalStackLayout>
    </ScrollView>
</ContentPage>

解决思路建议

  • 尝试将ScrollView的内容容器从VerticalStackLayout替换为Grid,StackLayout嵌套时易出现高度计算偏差,Grid的布局逻辑更稳定
  • 监听Entry的Focused事件,获取焦点时手动调用ScrollView的InvalidateMeasure()方法强制重新计算布局;或通过ScrollToAsync()将焦点元素滚动到可视区域
  • 检查Android项目的AndroidManifest.xml,确认无其他与窗口软键盘相关的配置冲突
  • 升级到.NET MAUI 10的最新补丁版本,这类滚动与软键盘交互问题大概率是已知bug,后续补丁通常会修复
  • 手动监听Android软键盘的显示/隐藏事件,弹出时调整ScrollView的底部内边距,确保内容可滚动到底部
  • 尝试使用Maui Community Toolkit的ScrollViewExtensions工具类,辅助处理滚动与焦点的交互逻辑

内容的提问来源于stack exchange,提问作者LiFix

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.02 06:54:50