簡體   English   中英

如何在Xamarin.Forms中調整Horizo​​ntal ListView的大小?

[英]How to adjust size of Horizontal ListView in Xamarin.Forms?

我看到此條目並嘗試,是的,滾動方向變為水平。

但是,視圖的大小不適合視圖的輪廓。

結果是這樣的:

Android結果iOS結果

即使旋轉視圖,如何調整視圖大小?

您可以使用相對布局來調整位置。 這是我使用旋轉的垂直列表視圖實現的水平列表視圖的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="ExampleProject.SomePage" >
    <ContentPage.Content>
        <RelativeLayout>
            <ListView x:Name="listView"
                      ItemsSource="{Binding ExampleList}"
                      RowHeight="120"
                      Rotation="270"
                      RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.5, Constant=-60}"
                      RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=-0.5, Constant=60}"
                      RelativeLayout.WidthConstraint="{ConstraintExpression Type=Constant, Constant=120}"
                      RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
                      >
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <ViewCell.View>
                                <Label Rotation="90"
                                       TranslationX="120" />
                            </ViewCell.View>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
            <StackLayout
                RelativeLayout.XConstraint="{ConstraintExpression Type=Constant, Constant=0}"
                RelativeLayout.YConstraint="{ConstraintExpression Type=Constant, Constant=120}"
                RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
                RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1, Constant=-120}"
                >
                <!-- Some content below list view -->
            </StackLayout>
        </RelativeLayout>
    </ContentPage.Content>
</ContentPage>

這應該適用於iOS和Android。

ListView是未經旋轉測量的。 如果將其設置為正方形,則旋轉后不應滲出屏幕。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM