xaml - 制作响应式框架 Xamarin 表单
问题描述
我试图在 Xamarin Forms 中进行压制。但没有运气。他是我的尝试。
<StackLayout Spacing="0" Padding="20">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="10"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Label x:Name="pol1" Text="some text" FontSize="Title" Grid.Row="1"/>
<Frame BackgroundColor="Gray" Grid.Row="2" HasShadow="True" CornerRadius="10">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="20"/>
<RowDefinition Height="200"/>
<RowDefinition Height="20"/>
<RowDefinition Height="5"/>
<RowDefinition Height="5"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackLayout Spacing="0">
<Label Text="some text" Grid.Row="2"/>
<Label Text="some text" Grid.Row="3"/>
<Label Text="some text" Grid.Row="4"/>
<Label Text="some text some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome text" Grid.Row="5"/>
<Label Text="some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome text" Grid.Row="6"/>
<Label Text="some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome text" Grid.Row="6"/>
</StackLayout>
</Grid>
</Frame>
</Grid>
</StackLayout>
但是框架不能缩放到文本。我想让它缩放到文本的末尾。
解决方案
StackLayout 的使用和这里的索引是问题所在。在这种情况下,父布局将无法正确测量尺寸。我已经删除了不需要的 StackLayouts 以使其优化。现在可以使用以下代码获得所需的结果。
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="10"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Label x:Name="pol1" Text="some text" FontSize="Title" Grid.Row="1"/>
<Frame BackgroundColor="Gray" Grid.Row="2" HasShadow="True" CornerRadius="10">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="20"/>
<RowDefinition Height="200"/>
<RowDefinition Height="20"/>
<RowDefinition Height="5"/>
<RowDefinition Height="5"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackLayout Spacing="0">
<Label Text="some text" Grid.Row="2"/>
<Label Text="some text" Grid.Row="3"/>
<Label Text="some text" Grid.Row="4"/>
<Label Text="some text some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome text" Grid.Row="5"/>
<Label Text="some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome text" Grid.Row="6"/>
<Label Text="some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome text" Grid.Row="6"/>
</StackLayout>
</Grid>
</Frame>
</Grid>
我得到了以下输出。我希望它对你有帮助。
推荐阅读
- sql - 如何将 unix 日期转换为雪花中的指定日期?
- wpf - 对于 UWP/WPF 项目的应用清单的可视资产部分,哪些是强制性的,哪些不是?
- sql - 使用 12 小时表示法格式化时间
- reactjs - 浏览多层 React 应用程序
- random - 从 U(1,3) 生成 U(1,5) 的最佳方法?
- android - 无法在 Kotlin 中创建类 com.example...ViewModel 的实例
- .net - 简单的 OData 客户端 - 如何将代理设置添加到 OData 客户端
- javascript - Angular Apollo 将 watchQuery 结果设置为可用变量
- javascript - 如何使用类似于 SQL 的 LIKE 运算符使用查询猫鼬?
- python - 使用 Python 编程编写一个函数以将给定的整数转换为罗马数字