listview - 如何在Xamarin.Forms中调整水平ListView的大小?

标签 listview xamarin xamarin.forms

我明白了this entry尝试一下,是的,滚动方向变成水平的。

但是, View 的大小不会根据 View 的轮廓进行调整。

结果如下:

Android result iOS result

即使 View 旋转,如何调整 View 的大小?

最佳答案

您可以使用相对布局来调整位置。这是我使用旋转的垂直 ListView 实现的水平 ListView 的 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 - 如何在Xamarin.Forms中调整水平ListView的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24439816/

相关文章:

xamarin.forms - 错误 : error MT1008: Failed to launch the simulator

mysql - 在 ListView 中应用多个过滤器

android - 如何使用 textwatcher 从 ListView 中搜索数据?

android - 如何在ListView中添加HeaderView

android - 在 XML 中的自定义 ScrollView 上膨胀类时出错?

android - ViewPager View 未显示

.net - 回归问题: XamlCompilation error Value cannot be null,参数名称:方​​法

android - 选择时无法突出显示我的 ListView 项目

c# - "Method too complex"抛出异常

android - 始终隐藏 Xamarin Forms Android 输入控件的键盘(条形码扫描仪输入)