我有一个非常广泛的图片链接,需要使用它作为视图的背景.对我来说很重要的是坚持图像的结束,顶部和底部的视图.由于画面太宽,我希望它离开屏幕左边.
我试过ConstraintLayout
和Box
,但没有达到.下面是我的代码:
@Composable
fun TestWide2() {
ConstraintLayout(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.background(color = colorResource(id = R.color.at_blue_transparent))
) {
val (image, content) = createRefs()
Image(
modifier = Modifier
.background(color = colorResource(id = R.color.at_white))
.fillMaxWidth()
.wrapContentHeight()
.constrainAs(image) {
top.linkTo(parent.top)
end.linkTo(parent.end)
bottom.linkTo(parent.bottom)
},
painter = painterResource(id = R.drawable.at_test_wide_small),
contentDescription = null,
contentScale = ContentScale.FillHeight,
alignment = Alignment.CenterEnd
)
Column(
modifier = Modifier
.constrainAs(content) {
top.linkTo(parent.top)
start.linkTo(parent.start)
bottom.linkTo(parent.bottom)
}
.fillMaxWidth()
.wrapContentHeight()
.padding(horizontal = 12.dp)
.padding(bottom = 5.dp, top = 3.dp)
) {
Text(
text = "Some text with unpredictable length placed on the left side of the screen",
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.padding(end = 100.dp, bottom = 2.dp),
)
CtaButton(
modifier = Modifier
.fillMaxWidth(0.85f)
.wrapContentHeight()
.padding(
end = 130.dp,
top = 20.dp
),
elevation = 0.dp,
text = "Button",
onPressed = { },
fontSize = 18.sp
)
}
}
}
And this is what I want to achieve:
在代码示例中是一个来自资源的文件,但在真正的代码中它是一个URL,所以我不能把它作为视图的背景. 由于文本可以由用户zoom ,图像和视图高度必须是动态的.