将文本与行中的容器/图标对齐

huangapple go评论50阅读模式
英文:

Aligning Text with Container/Icon in Row

问题

我的问题:将TextContainer / IconRow中对齐

当前输出:(我想要将这条蓝线与文本水平居中对齐)
将文本与行中的容器/图标对齐

预期输出:(红色水平线作为指南)
将文本与行中的容器/图标对齐

我的当前代码:

Row(
  mainAxisAlignment: MainAxisAlignment.center,
  children: [
    Text(
      'Unit Details',
      style: textTheme.bodyLarge,
    ),
    kHorizontalSpaceS,
    Container(
      height: 4,
      width: 42,
      decoration: BoxDecoration(
        color: Pallete.brandColor,
        borderRadius: BorderRadius.circular(16),
      ),
    ),
  ],
),

我对Text的基线了解不多,但我尝试过使用CrossAxisAlignment.baseline,但它不起作用。

我如何将这个蓝色的Container与文本水平对齐?

在将IconTextRow中对齐方面,我遇到了类似的问题。

英文:

My Issue: Aligning Text with Container / Icon in Row

Current Output: (I want to align this blue line with text horizontally center)
将文本与行中的容器/图标对齐

Expected Output: (Red horizontal line for a guideline)
将文本与行中的容器/图标对齐

My current code:

Row(
  mainAxisAlignment: MainAxisAlignment.center,
  children: [
    Text(
      'Unit Details',
      style: textTheme.bodyLarge,
    ),
    kHorizontalSpaceS,
    Container(
      height: 4,
      width: 42,
      decoration: BoxDecoration(
        color: Pallete.brandColor,
        borderRadius: BorderRadius.circular(16),
      ),
    ),
  ],
),

I have less knowledge about Text baseline, but I tried with CrossAxisAlignment.baseline but it's not working.

How can I horizontally align this blue Container with the text?

I faced a similar issue with aligning Icon and Text in Row.

答案1

得分: 1

我认为你应该使用mainAxisAlignment,因为它是一行。

英文:

I think you should use mainAxisAlignment since it is a row.

答案2

得分: 1

我认为问题可能出在TextStyle上,也许您的文本样式高度大于1,因为我在我的一侧使用TextStyle(fontSize:30)运行了您的代码,它运行正常。

英文:

I think that the problem can be in TextStyle, maybe your text style height is greater than one, cause I run your code in my side with TextStyle(fontSize:30), and it works fine.

答案3

得分: -1

Container(
height: 20,
alignment: Alignment.centerLeft,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [],
),
)

英文:

Can you wrap your code with Container and give needful height.

       Container(
        height: 20,
        alignment: Alignment.centerLeft,
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [],
        ),

huangapple
  • 本文由 发表于 2023年5月29日 13:03:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76354784.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定