简体   繁体   English

如何在 Jetpack Compose 中仅显示最后 3 行文本?

[英]How do I show only the last 3 lines of text in Jetpack Compose?

I have a Text object in Jetpack Compose whose content is continuously getting longer, but I only want to render the last 3 lines at any given time.我在 Jetpack Compose 中有一个Text对象,其内容不断变长,但我只想在任何给定时间渲染最后 3 行。 Essentially, I'm hoping to mimic the behavior of TextView 's android:gravity="bottom" , as seen here .从本质上讲,我希望模仿的行为TextViewandroid:gravity="bottom" ,因为看到这里 How would I go about achieving this?我将如何实现这一目标?

You can use maxLines in your Text function to render 3 Line and the gravity you can use align instead keep in mind you only allowed use align inside LayoutScope like Row Column Box etc. you can try thi code您可以在 Text 函数中使用 maxLines 来渲染 3 行,并且可以使用 align 代替重力,请记住,您只允许在 LayoutScope 内使用 align ,例如 Row Column Box 等。您可以尝试此代码

Row(modifier = Modifier.fillMaxSize()) {
      Text(
       text = "some text .....",
       modifier = Modifier.align(Alignment.Bottom),
       maxLines = 3
      )
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM