【问题标题】:Alexa APL. Problems getting AlexaHeader component to sit atop single Image component?Alexa APL。让 AlexaHeader 组件位于单个 Image 组件之上的问题?
【发布时间】:2020-05-14 20:42:23
【问题描述】:

我想在我的 Alexa Skill APL 页面顶部有一个标题,显示标题和子标题。在它的正下方,我想要一个图像。换句话说,我希望将标题和子标题放在图像顶部的一个框中,占据屏幕的顶行。

AlexaHeader 组件似乎非常适合这个。但是,当我在容器中将它用作第一个子项时,接下来将 Image 组件的 scale 属性设置为 best-fit,Image 组件会占据整个屏幕和 AlexaHeader 组件在图像后面,垂直居中,在 APL 页面的顶部。我可以在图像后面看到它,因为图像不会水平填充屏幕,只会垂直填充。

我怎样才能得到我想要的样子?

这是我正在使用的布局元素的 APL JSON:

"my-layout": {
    "type": "Alexa.Presentation.APL.RenderDocument",
    "token": "ABC_RENDERED_DOCUMENT",
    "version": "1.0",
    "document": {
        "type": "APL",
        "version": "1.0",
        "import": [
          {
                "name": "alexa-layouts",
                "version": "1.0.0"
          }
        ],
        "mainTemplate": {
            "description": "********* Minimal APL document **********",
            "parameters": [
                "payload"
            ],
            "items": [
                {
                    "type": "Container",
                    "width": "100%",
                    "height": "100%",
                    "alignItems": "center",
                    "justifyContent": "center",
                    "items": [
                        {
                            "type": "AlexaHeader",
                            "headerBackButton": true,
                            "headerBackButtonAccessibilityLabel": "back",
                            "headerBackgroundColor": "orange",
                            "headerTitle": "${payload.visualProperties.title}",
                            "headerSubtitle":"${payload.visualProperties.subtitle}",
                            "headerAttributionText": "photos by Pexels.com",
                            "headerAttributionImage": "https://d2o906d8ln7ui1.cloudfront.net/images/cheeseskillicon.png",
                            "headerAttributionPrimacy": true,
                            "headerDivider": true
                        },                            
                        {
                            "type": "Image",
                            "source": "${payload.visualProperties.background}",
                            "position": "absolute",
                            "width": "100vw",
                            "height": "100vh",
                            "scale": "best-fit"
                        }
                    ]
                }
            ]
        }
    },
    "datasources": {
        "visualProperties": {
            "background": "https://m.media-amazon.com/images/G/01/alexa-games/backgrounds/memorystory-gui-1._CB473869069_.png",
            "title": "",
            "subtitle": ""
        }
    }
}   

【问题讨论】:

    标签: alexa-skills-kit alexa-skill alexa-presentation-language


    【解决方案1】:

    您似乎设置了绝对定位,以便图像将显示在您的标题顶部(您只需要交换顺序)以及其他一些需要调整的项目。

    我可能误解了您的要求,但以下是我对您想要的最佳猜测。如果您需要任何调整,请告诉我。

    "my-layout": {
        "type": "Alexa.Presentation.APL.RenderDocument",
        "token": "ABC_RENDERED_DOCUMENT",
        "version": "1.0",
        "document": {
            "type": "APL",
            "version": "1.0",
            "import": [
                {
                    "name": "alexa-layouts",
                    "version": "1.0.0"
                }
            ],
            "mainTemplate": {
                "description": "********* Minimal APL document **********",
                "parameters": [
                    "payload"
                ],
                "items": [
                    {
                        "type": "Container",
                        "width": "100%",
                        "height": "100%",
                        "items": [
                        {
                            "type": "AlexaHeader",
                            "headerBackButton": true,
                            "headerBackButtonAccessibilityLabel": "back",
                            "headerBackgroundColor": "orange",
                            "headerTitle": "${payload.visualProperties.title}",
                            "headerSubtitle": "${payload.visualProperties.subtitle}",
                            "headerAttributionText": "photos by Pexels.com",
                            "headerAttributionImage": "https://d2o906d8ln7ui1.cloudfront.net/images/cheeseskillicon.png",
                            "headerAttributionPrimacy": true
                        },
                        {
                            "type": "Image",
                            "source": "${payload.visualProperties.background}",
                            "width": "100vw",
                            "height": "100vh",
                            "scale": "best-fit",
                            "align": "bottom"
                        }
                    ]
                    }
                ]
            }
        },
        "datasources": {
            "visualProperties": {
                "background": "https://m.media-amazon.com/images/G/01/alexa-games/backgrounds/memorystory-gui-1._CB473869069_.png",
                "title": "Header",
                "subtitle": "Header Subtitle"
            }
        }
    } 
    

    【讨论】:

    • 我不得不将图像的“比例”属性更改为“最适合”。不幸的是,图像组件没有调整大小以适应标题组件。相反,标题组件会剪切图像的顶部,因此您看不到图像的顶部 10%。换句话说,标题组件位于图像组件的“顶部”,并隐藏了它遮挡的图像部分。
    • 我可以知道为什么您需要最佳拟合,因为最佳拟合会导致图像周围出现黑色边框,除非您使用的图像与文档中的图像不同。同样要纠正重叠,只需删除图像上的绝对位置并交换顺序即可。我已经调整了答案以反映这一点。
    • 如果没有最佳拟合,它会拉伸图像并且看起来很糟糕。我知道黑色边框,这是保持纵横比和体面尺寸的代价。我可以通过编辑图像来解决这个问题。拉伸和调整大小对我来说是一个更糟糕的结果。
    • 当然可以。如果您实际上可以编辑图像,那么更好的结果是将“书”删除为独立的,并拥有一个额外的背景元素,即图像背景的颜色。将提取的书定位在底部,绝对定位背景元素。因此没有黑色边框,保留了纵横比。
    猜你喜欢
    • 1970-01-01
    • 2020-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-23
    • 2020-06-29
    相关资源
    最近更新 更多