JetPack Compose 使背景颜色仅填充屏幕的一部分
我正在撰写中使用线性渐变背景颜色。我希望它在屏幕的指定部分开始和停止,但目前它填满了整个屏幕。我该如何改变它。我需要它从屏幕下方 200 像素开始,高度为 250 像素,宽度为 350 像素。
这是我的线性渐变
val gradient = Brush.linearGradient(0.3f to Color.Green,1.0f to Color.Blue,start = Offset(0.0f, 50.0f),end = Offset(0.0f, 100.0f))
Box(modifier = Modifier.fillMaxSize().background(gradient))`
I'm working with a linear gradient background color in compose. I want it to start and stop at a designated portion of the screen but currently it's fill-in the whole screen. How can I change it. I need it to start 200px down the screen and have a height of 250px and a width of 350px.
Here's my linear gradient
val gradient = Brush.linearGradient(0.3f to Color.Green,1.0f to Color.Blue,start = Offset(0.0f, 50.0f),end = Offset(0.0f, 100.0f))
Box(modifier = Modifier.fillMaxSize().background(gradient))`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
drawBehind
并绘制一个矩形。您还必须更新 LinearGradient 偏移量。
You can use
drawBehind
and draw a rect.you have to update
LinearGradient
offset as well.您可以在
Box
上应用顶部填充,以“从屏幕下方 200 像素开始”:You can apply a top padding to your
Box
to "start 200px down the screen":