Jetpack compose:更改可组合的布局方向 [英] Jetpack compose: Change layout direction of a Composable

查看:55
本文介绍了Jetpack compose:更改可组合的布局方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将特定可组合的方向设置为 RTL

I want to set a direction of a specific composable to be RTL


@Composable
fun ViewToBeChanged() {
  Row {
     Image()
     Column {
        Text("Title")
        Text("Subtitle")
    }
  }
}

有可能吗?

Jetpack compose 布局文档提及LocalLayoutDirection

Jetpack compose Layout documentation mentions LocalLayoutDirection

通过更改 LocalLayoutDirection compositionLocal 来更改可组合的布局方向.

Change the layout direction of a composable by changing the LocalLayoutDirection compositionLocal.

但是我不知道如何在可组合中使用它才能生效.

But I have no idea how to use it in a composable to take effect.

推荐答案

您可以使用 CompositionLocalProvider 提供自定义 LocalLayoutDirection.

You can use the CompositionLocalProvider to provide a custom LocalLayoutDirection.

类似于:

CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl ) {
    Column(Modifier.fillMaxWidth()) {
        Text("Title")
        Text("Subtitle")
    }
}

这篇关于Jetpack compose:更改可组合的布局方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆