我正在嘗試鎖定標題的高度 - 或者基本上是頁面頂部的任何型別的內容。但是,一旦將可滾動內容添加到高度變化下方。一個簡單的例子:
<ContentPage.Content>
<StackLayout Padding="0" Margin="0" Spacing="0">
<Frame Margin="0" HeightRequest="150" BackgroundColor="red" CornerRadius="0" HasShadow="False" Padding="0"></Frame>
</StackLayout>
</ContentPage.Content>
這作業正常。但是,在滾動視圖中添加許多簡單的標簽線會以某種方式改變框架的高度。
<ContentPage.Content>
<StackLayout Padding="0" Margin="0" Spacing="0">
<Frame Margin="0" HeightRequest="150" BackgroundColor="red" CornerRadius="0" HasShadow="False" Padding="0"></Frame>
<ScrollView>
<StackLayout>
<Label Text="aaa" /> <!-- Repeated 54 times however removed here for simplicity-->
</StackLayout>
</ScrollView>
</StackLayout>
</ContentPage.Content>
結果最終是這樣的:

為什么會發生,我能做些什么來避免它嗎?為什么高度會降低到那個高度?謝謝!
uj5u.com熱心網友回復:
您似乎沒有限制 ScrollView 的高度。因此,考慮到您只是在執行 HeightRequest,它可能會根據需要進行更改以適合所有內容。使用網格通常更安全。在這個例子中,這樣的事情可以幫助你:
<ContentPage.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="150" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Frame Grid.Row="0" Margin="0" BackgroundColor="red" CornerRadius="0" HasShadow="False" Padding="0"></Frame>
<ScrollView Grid.Row="1">
<StackLayout>
<Label Text="aaa" /> <!-- Repeated 54 times however removed here for simplicity-->
</StackLayout>
</ScrollView>
</Grid>
</ContentPage.Content>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/406442.html
標籤:
