我正在使用xamarin表單。我在xaml中設計了一個登錄表單頁面。我想在出現鍵盤時向上移動登錄表單視圖,以便在平臺Android
和IOS
的情況下都可以看到文本字段和登錄按鈕。如何計算鍵盤高度並通過動態計算鍵盤高度來向上移動登錄表單視圖。xamarin表格:根據鍵盤高度向上移動視圖
下面是我的XAML代碼:
<ContentPage>
<ScrollView>
<AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Grid Padding="20, 30, 20, 20" RowSpacing="20" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Image Grid.Row="0" Source="login.png" HorizontalOptions="Center" VerticalOptions="Center"/>
<Entry Grid.Row="2" x:Name="entryUserName" HorizontalOptions="Fill" Placeholder="Username" PlaceholderColor="#707070" Text="{Binding UserName,Mode=TwoWay}" Margin="5"/>
<BoxView Grid.Row="2" HeightRequest="1" HorizontalOptions="Fill" BackgroundColor="#707070" VerticalOptions="End"/>
<Entry Grid.Row="3" x:Name="entryPassword" Text="{Binding Password,Mode=TwoWay}" Placeholder="Password" PlaceholderColor="#707070" Margin="5" HorizontalOptions="Fill" IsPassword="True"/>
<BoxView Grid.Row="3" HeightRequest="1" HorizontalOptions="Fill" BackgroundColor="#707070" VerticalOptions="End"/>
<Button Grid.Row="5" HorizontalOptions="Center" VerticalOptions="Center" Text="Login" Command="{Binding doLoginCommand}" CommandParameter="entryUserName,entryPassword" />
</Grid>
</AbsoluteLayout>
</ScrollView>
</ContentPage>
我不想執行任何種類的頁面定製渲染。是否有任何資源可以通過它編寫依賴項服務來計算不同移動視圖跨平臺的鍵盤高度。 我經歷了this,但它有一些我不想要的自定義渲染。
滾動視圖應該自動處理這爲你 – Jason
不,滾動視圖不會自動向上移動視圖。我需要滾動,然後滾動。我希望視圖自動切換而不滾動。 –
滾動視圖應該自動調整視圖,使焦點文本框不被鍵盤覆蓋。它可能不會調整整個視圖 – Jason