Xamarin Forms旋转列表视图调整行宽

2023-12-07

在 Xamarin Forms 中,我想实现一个水平列表视图(如下图所示)。通过旋转这是可能的,但我无法更改行宽。是否也有可能让第二个布局在第一个布局下开始? 提前致谢!

 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="Recipe.Pages.SearchPage"
         Title="Search">
<ContentPage.Content>
<StackLayout Spacing="5" x:Name="layout" Orientation="Vertical" >
  <StackLayout x:Name="layoutButtons" HorizontalOptions="FillAndExpand" Orientation="Horizontal" Spacing="5" BackgroundColor="Red">
    <Button x:Name="btn1" BackgroundColor="White" Image="@drawable/scan" />
    <Button x:Name="btn2" BackgroundColor="White" Image="@drawable/menu" />
    <Button x:Name="btn3" BackgroundColor="White" Image="@drawable/search" />
  </StackLayout>
  <StackLayout x:Name="layoutList" >
    <ListView  x:Name="listView" Rotation="270" RowHeight="75" >
      <ListView.ItemTemplate>
        <DataTemplate>
          <ViewCell>
            <StackLayout BackgroundColor="#eee" Orientation="Vertical" >
              <StackLayout Orientation="Horizontal" >
                <Button BackgroundColor="White" Rotation="90" Image="{Binding Recipe}" />
              </StackLayout>
          </StackLayout>
          </ViewCell>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>
  </StackLayout>
 </StackLayout>
 </ContentPage.Content>
</ContentPage>

enter image description here

EDIT我还尝试在列表视图中使用网格。有同样的问题。

 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="Recipe.Pages.SearchPage"
         Title="Search">
<ContentPage.Content>
<StackLayout Spacing="5" x:Name="layout" Orientation="Vertical" >
  <StackLayout x:Name="layoutButtons" HorizontalOptions="FillAndExpand" Orientation="Horizontal" Spacing="5" BackgroundColor="Red">
    <Button x:Name="btn1" BackgroundColor="White" Image="@drawable/scan" />
    <Button x:Name="btn2" BackgroundColor="White" Image="@drawable/menu" />
    <Button x:Name="btn3" BackgroundColor="White" Image="@drawable/search" />
  </StackLayout>
  <StackLayout x:Name="layoutList" >
    <ListView  x:Name="listView" Rotation="270" RowHeight="75" >
      <ListView.ItemTemplate>
        <DataTemplate>
          <ViewCell>
            <Grid>
              <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
              </Grid.RowDefinitions>
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="75" />
              </Grid.ColumnDefinitions>
              <Button Grid.Column="0" BackgroundColor="White" Rotation="90" Image="{Binding Recipe}" />
            </Grid>
          </ViewCell>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>
  </StackLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>

我也面临同样的问题。我使用下面的 xaml 代码来管理高度和宽度ListView.

<?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="VCRoom.HorizontalScroll">
  <ContentPage.Content >
    <RelativeLayout>
      <ListView x:Name="TestListView"
                RowHeight="80"
                Rotation="270"
                RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.5, Constant=-40}"
                RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=-0.5, Constant=40}"
                RelativeLayout.WidthConstraint="{ConstraintExpression Type=Constant, Constant=80}"
                RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
                >
      </ListView>
    </RelativeLayout>
  </ContentPage.Content>
</ContentPage>

Change RowHeight and Constant in XConstraint and YConstraint管理水平的宽度和高度ListView因此。

仅供参考下面是我用来填充的自定义单元格ListView项目。我在每个列表项中显示垂直标签。

<?xml version="1.0" encoding="UTF-8"?>
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="VCRoom.TestCell">
  <ViewCell.View>

      <StackLayout Orientation="Horizontal" HorizontalOptions="End" VerticalOptions ="Center">
        <Label Rotation="90" Text="{Binding Day}"  TextColor="#000000" HorizontalOptions="StartAndExpand" VerticalOptions="Start"/>
        <Label Rotation="90" Text="{Binding mDate}" TextColor="#000000" HorizontalOptions="StartAndExpand" VerticalOptions="Start"/>
      </StackLayout>

  </ViewCell.View>
</ViewCell>

希望这对未来的用户有所帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Xamarin Forms旋转列表视图调整行宽 的相关文章

随机推荐

  • 在 C 中对齐 printf() 变量和小数

    今天C的大问题 所以我希望我的变量在列中对齐并且同时保留两位小数 我知道要达到小数点后两位 我需要使用 2f 如果我想要宽度 我使用 30s 但我无法将它们结合起来 看看我下面的代码你就会明白了 printf ItemA 2f 3 34 2
  • 宽松的内存顺序效果是否可以延长到执行线程的生命周期之后?

    假设在 C 11 程序中 我们有一个名为A启动一个名为的异步线程B 内螺纹B 我们对原子变量执行原子存储std memory order relaxed记忆顺序 然后穿线A用线程连接B 然后穿线A启动另一个名为C执行原子加载操作std me
  • 让调用堆栈向上增长会使缓冲区溢出更安全吗?

    每个线程都有自己的堆栈来存储局部变量 但堆栈也用于存储返回地址调用函数时 在 x86 汇编中 esp指向最近分配的堆栈末尾 如今 大多数 CPU 的堆栈都出现负增长 此行为可以通过溢出缓冲区并覆盖保存的返回地址来执行任意代码 如果堆栈正向增
  • 如何设置ImageView透明

    我的图像设置为 50 透明 当我把它放到ImageView上时 它完全不透明 看不到后面的东西 如何在xml中为ImageView设置100 透明 以便当我设置图像时 我可以看到后面的东西 我试过 android opacity trans
  • 表格行上的框阴影未出现在某些浏览器上

    表格行上的 CSS 框阴影 tr 跨浏览器的工作似乎不一致 在某些浏览器上会显示阴影 在其他人身上 没有影子 我正在使用以下 CSS tr background color rgb 165 182 229 box shadow 0px 2p
  • 如何取消设置 JavaScript 变量?

    我在 JavaScript 中有一个全局变量 实际上是一个window属性 但我认为这并不重要 它已经由以前的脚本填充 但我不希望稍后运行另一个脚本来查看它的值 或者甚至定义它 我已经把some var undefined它用于测试目的ty
  • Excel VBA 对于带有数据验证列表的每个循环

    我有 4 个数据验证下拉列表 我想使用 for every 循环来迭代 4 个数据验证下拉列表的所有可能值 并将结果复制到工作表中 下拉菜单位于单元格 H3 和 H4 以及 U3 和 U4 中 H3 和 U3 包含相同的值 H4 和 U4
  • 字符编码 - RequestDispatcher

    我有一个 servlet 我使用 String error error request setAttribute loginError error request setCharacterEncoding UTF 8 request get
  • 如何导出 Spearman 相关性

    我正在尝试将 Spearman 相关矩阵导出到rtf或 Excel 文件使用estpost和社区贡献的命令esttab 但是 我收到以下错误 invalid subcommand r 198 下面是我的代码 estpost spearman
  • ASIO 直接从异步解析获取 tcp 端点

    我正在寻找使用 ASIO 独立库 不是 Boost ASIO 我正在尝试设置客户端以连接到特定端口上的服务器 我看到在波特漏斗例如 无需处理迭代器即可获取端点 asio io service io service Determine the
  • Xcode:为什么“用户交互已启用”出现两次?

    这个问题适用于 Xcode 3 和 4 为什么这个复选框出现两次 在身份检查器和属性检查器下 更重要的是 为什么改变一个值不会影响另一个值呢 身份检查器中启用的用户交互指的是可访问性协议 这是一个链接无障碍编程指南您可以勾选不同的特征来修改
  • jquery新手:将验证与隐藏提交按钮结合起来

    我是 jQuery 新人 我已经验证可以使用我的表单 MVC 1 0 C
  • 如何在VBA中对变量范围内的值求和?

    我有一张表格 如下所示 在 C 列中 如果 A 列具有相同的索引 B 列 我想对 A 列中的值求和 如果所有行具有相同的索引 如 D 列所示 我想对所有行输入总和结果 不幸的是 具有相同索引的值的范围是可变的 我的宏可以仅使用 2 个索引对
  • python sendall 未引发连接关闭错误

    我有以下代码 在 linux mac 远程和本地计算机上使用 python2 7 和 python3 5 进行了测试 import socket import time s socket socket s connect 127 0 0 1
  • 无法解码流 java.io.FileNotFoundException /storage/emulated/0 打开失败:ENOENT(没有这样的文件或目录

    你好 我正在尝试保存在我的应用程序上拍摄的图片 但是当我尝试访问内存来放置数据时 出现错误 无法解码流 java io FileNotFoundException storage emulated 0 打开失败 ENOENT 没有这样的文件
  • 获取 Facebook 上好友的好友列表

    我最近开始研究 Facebook API 并试图找出如何检索另一个用户的朋友列表 在本例中 该用户是我的朋友 到目前为止 我只知道如何找到我也是朋友的人的朋友 然而 Friends Wheel 应用程序可以做到这一点 因为您可以为您的一位朋
  • 如何确定C++函数调用顺序?

    我将跳过标题 class X int i static int j public X int ii 1 i ii j i static int incr return j static int f return incr int tmain
  • 在 WordPress 中上传期间重命名文件

    我正在尝试重命名上传文件名以匹配帖子标题 另一个线程显示了如何重命名为哈希 在 WordPress 后端上传期间重命名文件 使用此代码 function make filename hash filename info pathinfo f
  • 在 Firefox 扩展中按域名/名称访问特定 cookie

    我正在开发一个 Firefox 扩展 需要从特定域访问特定 cookie 我有这段代码 可以获取所有域的所有 cookie 我如何仅请求我正在查找的 cookie var Cc Ci require chrome var cookieMan
  • Xamarin Forms旋转列表视图调整行宽

    在 Xamarin Forms 中 我想实现一个水平列表视图 如下图所示 通过旋转这是可能的 但我无法更改行宽 是否也有可能让第二个布局在第一个布局下开始 提前致谢