xamarin 如何在以下xaml代码中使表视图可滚动

wribegjk  于 2022-12-07  发布在  其他
关注(0)|答案(2)|浏览(118)

我想用xaml设计一个用户界面页面,其中我想在页面顶部保留图像ballotInfo.png,在底部保留按钮Next。用户应该能够滚动浏览其余的内容。我尝试使用scrollview使table视图可滚动,但效果不理想。请帮助。以下是XAML正在处理代码。

<AbsoluteLayout>
<RelativeLayout>
    <Image Source = "ballotInfo.png" Aspect="Fill" x:Name="headerImage"
        RelativeLayout.WidthConstraint = "{ConstraintExpression
            Type=RelativeToParent,
            Property=Width,
            Factor = 1}" 

        RelativeLayout.HeightConstraint = "{ConstraintExpression
            Type = RelativeToParent,
            Property=Height,
            Factor=0.35}"/>

<StackLayout x:Name="entryLayout" VerticalOptions="FillAndExpand"   Padding="0"
            RelativeLayout.YConstraint = "{ConstraintExpression
                Type=RelativeToView,
                ElementName=headerImage,
                Property=Height,
                Factor=1}">

        <TableView Intent="Form" HasUnevenRows = "true"  >
            <TableView.Root>
                <TableSection Title="Local Admin: Ajay" >
                    <ViewCell>
                        <StackLayout Orientation="Horizontal" Padding="10,0,10,0" >
                            <Label Text="Ballot Title" VerticalOptions="Center" TextColor="#a2a1b8" />
                            <Entry HorizontalOptions="FillAndExpand" FontAttributes="Bold" HorizontalTextAlignment="End" TextColor="#151431" />
                        </StackLayout>
                    </ViewCell>
                    <ViewCell Height="200" >
                        <StackLayout Orientation="Horizontal" Padding="10,0,10,0">
                            <Label Text="Ballot Description" VerticalOptions="Center" TextColor="#a2a1b8"/>
                            <Editor  VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" FontSize="Small" TextColor="#151431" />
                        </StackLayout>
                    </ViewCell>
                    <ViewCell>
                        <StackLayout Orientation="Horizontal" Padding="10,0,10,0">
                            <Label Text = "Ballot End Date" HorizontalOptions="Center" VerticalOptions="Center" TextColor="#a2a1b8" />
                        <StackLayout HorizontalOptions="EndAndExpand"  >
                            <DatePicker Date="{x:Static sys:DateTime.Today}" TextColor="#151431" />
                        </StackLayout>
                    </StackLayout>
                    </ViewCell>
                    <ViewCell >
                        <StackLayout Orientation="Horizontal" VerticalOptions="Fill"  Padding="10,0,10,0" >
                            <Label Text="No. of Candidates" VerticalOptions="Center" TextColor="#a2a1b8" />
                            <Entry HorizontalOptions="FillAndExpand" Keyboard="Numeric" HorizontalTextAlignment="End" TextColor="#151431" />
                        </StackLayout>
                    </ViewCell>
                </TableSection>
            </TableView.Root>
        </TableView>

</StackLayout>

</RelativeLayout>
    <Grid
        AbsoluteLayout.LayoutBounds="0.5, 1, 1,AutoSize"
        AbsoluteLayout.LayoutFlags="PositionProportional,WidthProportional">
        <Button Text="Next" 
        VerticalOptions="End" 
        TextColor="White"
        FontSize="15" 
        BackgroundColor="#ff2d55"/>
    </Grid>
    </AbsoluteLayout>
ehxuflar

ehxuflar1#

替换网格的AbsoluteLayout/RelativeLayout是一个更简洁的解决方案。以下是为您提供的模板:

<Grid
        ColumnSpacing="0"
        RowSpacing="0">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Image Grid.Row="0" />
    <ScrollView Grid.Row="1">
        <StackLayout
                Padding="0"
                x:Name="entryLayout">
        </StackLayout>
    </ScrollView>
    <Button
            Grid.Row="2"
            HorizontalOptions="Center"
            Text="Next"
        />
</Grid>
xjreopfe

xjreopfe2#

我是xaml的新手,但似乎xaml中没有ScrollView,但xamarin中有。我尝试了这个解决方案,但没有成功。然而,我使用了ScrollViewer,它完成了这项工作。

相关问题