【问题标题】:Position icon top right hand corner of frame xamarin forms框架 xamarin 表单的位置图标右上角
【发布时间】:2019-11-16 14:07:32
【问题描述】:

我想在框架的右上角放置一个图标。 我不得不承认我读过很多次关于绝对布局的文章,但显然不是在我的脑海里。

从图片中可以看出,图标有点出,这是代码

错误的示例代码!

<AbsoluteLayout>
    <Frame
        Margin="10"
        Padding="10"
        AbsoluteLayout.LayoutBounds="0,0,1,1"
        AbsoluteLayout.LayoutFlags="All"
        BorderColor="Blue"
        CornerRadius="5"
        HasShadow="False">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Label Grid.Row="0" Text="sample" />
            <Label Grid.Row="1" Text="sample2" />
        </Grid>
    </Frame>
    <ContentView AbsoluteLayout.LayoutBounds="1, 0, -1, -1" 
                 AbsoluteLayout.LayoutFlags="PositionProportional">

        <Image Source="myIcon.png" />
    </ContentView>
</AbsoluteLayout>

有什么建议吗?

【问题讨论】:

    标签: xamarin.forms absolutelayout


    【解决方案1】:

    为您的图标指定一个特定的宽度和高度,并将 Frame 的边距设置为一个比例值。您可以更改 Frame 的边距值以使其适合您的喜好:

    <AbsoluteLayout>
        <Frame
            Margin="10"
            Padding="10"
            AbsoluteLayout.LayoutBounds="0,0,1,1"
            AbsoluteLayout.LayoutFlags="All"
            BorderColor="Blue"
            CornerRadius="5"
            HasShadow="False">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Label Grid.Row="0" Text="sample" />
                <Label Grid.Row="1" Text="sample2" />
            </Grid>
        </Frame>
        <Image AbsoluteLayout.LayoutBounds="1, 0, 25, 25"
               AbsoluteLayout.LayoutFlags="PositionProportional"
               Source="myIcon.png" Aspect="AspectFit" />
    </AbsoluteLayout>
    

    【讨论】:

    • 感谢您的回复,但图标完全消失了
    • 更正。当我想在右上角时,图标不会消失,但会出现在框架内。
    • 感谢您的帮助。你能解释一下你做了什么。那行得通
    • AbsoluteLayout 和 Frame 之间需要有一定的空间,以便我们的图标放置在 Frame 的上方和右侧一点,您已经通过将 Margin="10" 设置为 Frame(值需要接近图标宽度/高度值的一半)。然后我们将图标放在 AbsoluteLayout 的右上角,并为其宽度和高度赋予 25 的值。
    猜你喜欢
    • 1970-01-01
    • 2018-10-17
    • 1970-01-01
    • 2022-11-17
    • 2014-09-12
    • 2012-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多