简体   繁体   English

Xamarin表单:带有KeyBoard的ScrollView

[英]Xamarin Forms: ScrollView with KeyBoard

I am on the most current version of Xamarin Forms. 我是Xamarin Forms的最新版本。 I have a Content Page. 我有一个内容页面。 The Content Page has a grid that has a scrollview that has a stacklayout that contains some image and Entry inputs and some Buttons. 内容页面有一个网格,其滚动视图的stacklayout包含一些图像和条目输入以及一些按钮。 When I touch the Entry to enter text, the keyboard covers the Buttons so I can't press the button. 当我触摸条目输入文本时,键盘覆盖按钮,所以我不能按下按钮。 This isn't scrollable and I don't know why. 这不可滚动,我不知道为什么。 Anybody can help me? 有人可以帮帮我吗?

Here is my XAML code: 这是我的XAML代码:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="Spirocco.LoginPage">
<Grid>
    <ScrollView Orientation="Both" x:Name="scrollView">
        <ScrollView.Content>
            <StackLayout BackgroundColor="#302138">
                <Image Source="login_logo" Margin="0,0,0,0"></Image>
                <StackLayout BackgroundColor="White" Margin="20,0,20,30">
                    <Label Text="ÜDVÖZÖLJÜK!" FontSize="30" FontFamily="Comic Sans MS" Margin="0,15,0,0" TextColor="#302138" HorizontalTextAlignment="Center"></Label>
                    <Entry Text="{Binding Email}" Placeholder="E-mail" Margin="40,0,40,0" Keyboard="Email"/>
                    <Entry Text="{Binding Password}" Placeholder="Jelszó" IsPassword="True" Margin="40,0,40,0"/>
                    <Button Text="BEJELENTKEZÉS" Clicked="Login" TextColor="White" BackgroundColor="#302138" Margin="40,10,40,0"/>
                    <Button Text="REGISZTRÁCIÓ" Clicked="Register" TextColor="White" BackgroundColor="#302138" Margin="40,0,40,25"/>
                </StackLayout>
            </StackLayout>
        </ScrollView.Content>
    </ScrollView>
</Grid>

Here is the solution 这是解决方案

Just add this code to App.xaml.cs to make page auto-resizable 只需将此代码添加到App.xaml.cs即可使页面自动调整大小

using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;

public partial class App : Xamarin.Forms.Application
{
    public App ()
    {
        Xamarin.Forms.Application.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
        InitializeComponent();

        MainPage = new NavigationPage(new LoginTabsPage()){
        ...

在此输入图像描述

By default, grid's row height value will be equals to '*' and therefore will take all the space in the screen. 默认情况下,网格的行高值将等于'*',因此将占用屏幕中的所有空间。 This is why it is not scrollable. 这就是它不可滚动的原因。

By the way, I don't really get why you nest in into a grid. 顺便说一下,我真的不明白你为什么要陷入网格。

Try this: 试试这个:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
     x:Class="Spirocco.LoginPage">

<ScrollView Orientation="Both" x:Name="scrollView">
    <ScrollView.Content>
        <StackLayout BackgroundColor="#302138">
            <Image Source="login_logo" Margin="0,0,0,0"></Image>
            <StackLayout BackgroundColor="White" Margin="20,0,20,30">
                <Label Text="ÜDVÖZÖLJÜK!" FontSize="30" FontFamily="Comic Sans MS" Margin="0,15,0,0" TextColor="#302138" HorizontalTextAlignment="Center"></Label>
                <Entry Text="{Binding Email}" Placeholder="E-mail" Margin="40,0,40,0" Keyboard="Email"/>
                <Entry Text="{Binding Password}" Placeholder="Jelszó" IsPassword="True" Margin="40,0,40,0"/>
                <Button Text="BEJELENTKEZÉS" Clicked="Login" TextColor="White" BackgroundColor="#302138" Margin="40,10,40,0"/>
                <Button Text="REGISZTRÁCIÓ" Clicked="Register" TextColor="White" BackgroundColor="#302138" Margin="40,0,40,25"/>
            </StackLayout>
        </StackLayout>
    </ScrollView.Content>
</ScrollView>

The Solution is Here 解决方案就在这里

It wasn't scrollable because in the stacklayout doesn't have enough content. 它不可滚动,因为在stacklayout中没有足够的内容。 I able to do this. 我能做到这一点。 This is not a very nice solution but works. 这不是一个非常好的解决方案,但有效。 I put a label width HeighRequest and same color with StackLayout and now the page is scrollable when I type my password. 我在StackLayout中放置了标签宽度HeighRequest和相同的颜色,现在当我输入密码时页面可以滚动。

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="Spirocco.LoginPage">
<ContentPage.Content>
    <ScrollView Orientation="Both" x:Name="scrollView">
        <ScrollView.Content>
            <StackLayout BackgroundColor="#302138">
                <Image Source="login_logo" Margin="0,0,0,0"></Image>
                <StackLayout BackgroundColor="White" Margin="20,0,20,30">
                    <Label Text="ÜDVÖZÖLJÜK!" FontSize="30" FontFamily="Comic Sans MS" Margin="0,15,0,0" TextColor="#302138" HorizontalTextAlignment="Center"></Label>
                    <Entry Text="{Binding Email}" Placeholder="E-mail" Margin="40,0,40,0" Keyboard="Email"/>
                    <Entry Text="{Binding Password}" Placeholder="Jelszó" IsPassword="True" Margin="40,0,40,0"/>
                    <Button Text="BEJELENTKEZÉS" Clicked="Login" TextColor="White" BackgroundColor="#302138" Margin="40,10,40,0"/>
                    <Button Text="REGISZTRÁCIÓ" Clicked="Register" TextColor="White" BackgroundColor="#302138" Margin="40,0,40,25"/>
                </StackLayout>
                <Label BackgroundColor="#302138" HeightRequest="160"/>
            </StackLayout>
        </ScrollView.Content>
    </ScrollView>
</ContentPage.Content>

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

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