在Android6.0 Marshmellow上,我对Xamarin表单的绝对布局有一个问题
当设置一个视图来填充整个屏幕时,屏幕底部会留下一个1 1px的空白。
奇怪的是,如果你把屏幕旋转成景观,就不会发生这种情况。或关于4.4
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="XamarinTest.Page1">
<AbsoluteLayout BackgroundColor="White">
<BoxView BackgroundColor="Red" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All">
</BoxView>
</AbsoluteLayout>
</ContentPage>屏幕截图:(这些来自vs模拟器,但我在设备上也有相同的行为,如三星星系6)。

在本例中,我在屏幕上使用了一个boxview文件,但它是与屏幕底部对齐的任何位置。
我正在寻找的是某种解决方案或自定义渲染器,它将确保在1,1或拉伸屏幕的全部高度的项目被放置在或延伸到屏幕的底部。
发布于 2016-04-18 17:11:00
这是在Xamarin.Forms 2.1.0:bug.cgi?id=40092中确认的错误。
您可以尝试通过重写LayoutChildren并向基本实现多发送一个高度像素来修复它。
public class MyAbsoluteLayout : AbsoluteLayout
{
protected override void LayoutChildren(double x, double y, double width, double height)
{
base.LayoutChildren(x, y, width, height+1);
}
}然后在XAML中使用它
<local:MyAbsoluteLayout BackgroundColor="White">
<BoxView BackgroundColor="Red" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All">
</BoxView>
</local:MyAbsoluteLayout>如果这没有帮助,您可以尝试重新实现LayoutChildren函数并操作结果,如
public class MyAbsoluteLayout : AbsoluteLayout
{
private readonly MethodInfo _computeLayout;
public MyAbsoluteLayout()
{
_computeLayout = typeof(AbsoluteLayout).GetTypeInfo().GetDeclaredMethod("ComputeLayoutForRegion");
}
protected override void LayoutChildren(double x, double y, double width, double height)
{
foreach (View logicalChild in Children)
{
Size region = new Size(width, height);
Rectangle layoutForRegion = (Rectangle)_computeLayout.Invoke(null, new object[] { logicalChild, region });
layoutForRegion.X += x;
layoutForRegion.Y += y + 1;
Rectangle bounds = layoutForRegion;
logicalChild.Layout(bounds);
}
}
}https://stackoverflow.com/questions/36692647
复制相似问题