繁体   English   中英

Xamarin表单编辑器将控件推开了

[英]Xamarin forms editor push controls out of the scream

我是xamarin形式的初学者,我需要创建一个包含一些标签和编辑器的页面。 我想要Android中的默认键盘重叠:WindowSoftInputModeAdjust.Pan。 当我在编辑器中编写内容时,以及在键盘弹起时可以显示的最大最大尺寸时,它将标签从尖叫声中挤出来。 如何禁用编辑器将标签从尖叫中推出,但同时又可以在其中滚动文本?

    <StackLayout>
        <Label Text="First"/>
        <Label Text="Second"/>
        <Label Text="Third"/>
        <Label Text="Fourth"/>
        <Label Text="Fifth"/>
        <Label Text="Sixth"/>
        <Editor HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="Red" />
    </StackLayout>

您必须将编辑器放入stacklayout

<StackLayout>
    <Label Text="First"/>
    <Label Text="Second"/>
    <Label Text="Third"/>
    <Label Text="Fourth"/>
    <Label Text="Fifth"/>
    <Label Text="Sixth"/>
    <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
            <Editor VerticalOptions="FillAndExpand" BackgroundColor="Red" />
    </StackLayout>
</StackLayout>

以我的理解,发生这种情况的原因是因为VerticalOptions="FillAndExpand"

阅读文档时,它会显示:

StartAndExpand,CenterAndExpand,EndAndExpand和FillAndExpand值用于定义对齐方式首选项,以及视图是否在父StackLayout中可用时是否占用更多空间。

我建议您将其删除,然后重试!

有关更多信息,请检查: https : //docs.microsoft.com/zh-cn/xamarin/xamarin-forms/user-interface/layouts/layout-options

更新资料

您的代码应如下所示:

<Grid> 
<Grid.RowDefinitions>
<Grid.RowDefinition Height="Auto"/>
<Grid.RowDefinition Height="*"/>
</Grid.RowDefinitions>
 <StackLayout Grid.Row="0">....<StackLayout> //all the labels here
  <Editor Grid.Row="1" VerticalOptions="FillAndExpand" .../>
 </Grid>

编辑

我正在使用以下代码,它在Xamarin.Forms 4.2上的工作原理像一个超级按钮,我还附加了一个屏幕截图供您查看外观。

 <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <StackLayout Grid.Row="0">
            <Label Text="First" />
            <Label Text="Second" />
            <Label Text="Third" />
            <Label Text="Fourth" />
            <Label Text="Fifth" />
            <Label Text="Sixth" />
        </StackLayout>
        <Editor
            Grid.Row="1"
            AutoSize="Disabled"
            BackgroundColor="Red"
            HorizontalOptions="FillAndExpand"
            VerticalOptions="FillAndExpand" />
    </Grid>

编辑

如何禁用编辑器将标签从尖叫中推出,但同时又可以在其中滚动文本?

如果要执行此操作,建议您不要将“编辑器” verticaloptions设置为FillAndExpand,否则它将始终将控件推出屏幕。

<StackLayout>
        <Label Text="First" />
        <Label Text="Second" />
        <Label Text="Third" />
        <Label Text="Fourth" />
        <Label Text="Fifth" />
        <Label Text="Sixth" />
        <ScrollView>
            <Editor
                x:Name="editor"
                BackgroundColor="Red"
                HorizontalOptions="FillAndExpand"
                VerticalOptions="FillAndExpand" />

        </ScrollView>

    </StackLayout>

更新:

我需要编辑器占用标签下所有可用的空间,而不是默认高度或必要的高度thnx。

您可以在App()构造函数中调用以下代码。

 Xamarin.Forms.Application.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);

并使用Scrollview进行滚动。

<StackLayout>
        <Label Text="First" />
        <Label Text="Second" />
        <Label Text="Third" />
        <Label Text="Fourth" />
        <Label Text="Fifth" />
        <Label Text="Sixth" />
        <ScrollView VerticalOptions="FillAndExpand">
            <Editor
                x:Name="editor"
                BackgroundColor="Red"
                HorizontalOptions="FillAndExpand"
                VerticalOptions="FillAndExpand" />

        </ScrollView>

    </StackLayout>

屏幕截图如下:

在此处输入图片说明

暂无
暂无

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

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