Xamarin - 视图的下半部分被切断 [英] Xamarin - lower half of view cut off

查看:24
本文介绍了Xamarin - 视图的下半部分被切断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时在加载视图时,它不会在 Iphone 上完全加载.. 看截图..(图像是故意模糊的..)至少,它没有以适当的尺寸加载.它通常通过将手机旋转到横向和向后来修复..有没有办法避免这种情况?

Some times when loading a View, it does not fully load on Iphone.. see the screenshot.. (Images are blurred on purpose..) At least, it does not load with proper dimensions. it is usually fixed by rotating the phone to landscape and back.. is there a way to avoid 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"
             xmlns:vm="clr-namespace:GalShare.ViewModel"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
             xmlns:forms="clr-namespace:RedCorners.Forms;assembly=RedCorners.Forms"
             mc:Ignorable="d"
             x:Class="GalShare.Views.Gallery">

    <NavigationPage.TitleView>
        <Grid Padding="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="100"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="180"/>
                <ColumnDefinition Width="10"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="45"/>
            </Grid.RowDefinitions>
            <Button Grid.Row="0" Grid.Column="0" Text="Back" x:Name="Backbutton" Clicked="Backbutton_Clicked"></Button>
            <Button Grid.Row="0" Grid.Column="2" Text="Ph. contact info" x:Name="PhInfo" Clicked="PhInfo_Clicked"></Button>
        </Grid>
    </NavigationPage.TitleView>

    <ContentPage.Content>
    <AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
            <StackLayout
                 AbsoluteLayout.LayoutFlags="All"
                 AbsoluteLayout.LayoutBounds="0,0,1,1">
                <ContentView x:Name="Messagecontainer" Padding="5">
                    <forms:Frame2 CornerRadius="8"  
                               HasShadow="True"
                               ShadowRadius="8"    
                               ShadowColor="Black"
                               Padding="5"                               
                               BackgroundColor="LightGray">

                        <Label x:Name="Messagefield"></Label>
                    </forms:Frame2>
                </ContentView>
                <CollectionView ItemsSource="{Binding Galleries}" Margin="0" x:Name="MyCollection" SelectionMode="Single" SelectionChanged="CollectionView_SelectionChanged">
                    <CollectionView.ItemsLayout>
                        <GridItemsLayout Orientation="Vertical"                                 
                                Span="2" />

                    </CollectionView.ItemsLayout>
                    <CollectionView.ItemTemplate>
                        <DataTemplate>
                            <ContentView Padding="8">
                                <forms:Frame2 CornerRadius="15"  
                                       HasShadow="True"
                                       ShadowRadius="5"   
                                       HeightRequest="190"
                                       BackgroundColor="LightGray"
                                       Padding="1">
                                    <StackLayout HorizontalOptions="Start" VerticalOptions="Start" Padding="2">
                                        <Grid>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="140"/>
                                                <RowDefinition Height="*"/>
                                            </Grid.RowDefinitions>
                                            <ffimageloading:CachedImage Grid.Row="0" Grid.Column="0" x:Name="myImage" Source="{Binding ThumbUrl}" Aspect="AspectFit" CacheDuration="1" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" DownsampleToViewSize="False"></ffimageloading:CachedImage>
                                            <StackLayout Padding="0"  Margin="0"  Spacing="0" Grid.Column="0" Grid.Row="1">
                                                <StackLayout Spacing="0" Margin="0" Padding="5,0,5,0">
                                                    <ImageButton HorizontalOptions="Center" Padding="0" WidthRequest="28" Aspect="AspectFit" HeightRequest="28" Margin="0" Source="{Binding likeImg}" x:Name="Favoriteimage" Clicked="LikeButton_Clicked" ></ImageButton>
                                                 <!--   <Button CharacterSpacing="0"  HorizontalOptions="Center" Padding="0" WidthRequest="50" HeightRequest="28" Margin="0" Text="Like" x:Name="Favoriteimage" Clicked="Button_Clicked" ></Button>-->
                                                </StackLayout>
                                                    <Label x:Name="Picname" Text="{Binding ImageName}" IsVisible="{Binding showname}" FontSize="Micro" VerticalOptions="End" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" ></Label>
                                            </StackLayout>
                                        </Grid>
                                    </StackLayout>
                                </forms:Frame2>
                            </ContentView>
                        </DataTemplate>
                    </CollectionView.ItemTemplate>
                </CollectionView>
            </StackLayout>
            <StackLayout IsVisible="{Binding isBusy}" x:Name="LoadingLayout" Padding="12"
                 AbsoluteLayout.LayoutFlags="PositionProportional"
                 AbsoluteLayout.LayoutBounds="0.5,0.5,-1,-1">
                <ActivityIndicator IsVisible="{Binding IsBusy}" 
                               IsRunning="{Binding IsBusy}" />
                <Label Text="Loading gallery..." IsVisible="{Binding IsBusy}" HorizontalOptions="Center" TextColor="Black"/>
            </StackLayout>
        </AbsoluteLayout>

    </ContentPage.Content>
</ContentPage>

推荐答案

因为您使用 AbsoluteLayout 作为 ContentPage 的根布局.如果您想将 ActivityIndi​​cator 放在 CollectionView 上,您可以使用 Grid 并将它们放在同一个单元格中.

Because you used AbsoluteLayout as root layout of the ContentPage . If you want to put the ActivityIndicator on the CollectionView , you could use Grid and put them in the same cell .

<Grid VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>

        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>


        <StackLayout  Grid.Row="0" Grid.Column="0" BackgroundColor="Red"  x:Name="LoadingLayout" Padding="12">

           //...
        </StackLayout>

        <StackLayout Grid.Row="0" Grid.Column="0" IsVisible="{Binding isBusy}" x:Name="LoadingLayout" Padding="12" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
                <ActivityIndicator IsVisible="{Binding IsBusy}" 
                               IsRunning="{Binding IsBusy}" />
                <Label Text="Loading gallery..." IsVisible="{Binding IsBusy}" HorizontalOptions="Center" TextColor="Black"/>
        </StackLayout>

</Grid>

如果问题仍然存在,您可以分享您的样本,以便我可以在我这边进行测试.

If the problem still exists, you could share your sample so that I can test it on my side .

这篇关于Xamarin - 视图的下半部分被切断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆