layoutweight(1)不能优先展示指定的组件

1、希望在副标题超长的情况下,主标题‘正文列表’优先展示显示,副标题结尾是省略号,现在给主标题设置layoutweight(1)不能达到预期

2、代码倒数第五行组件偏移设置为 margin后,副标题组件超出屏幕被截断,此处怎么理解

3、假如设置width(‘90%’),里面的90%是屏幕的90%还是父容器的90%

@Entry 
@Component 
struct Index { 
  private hasMore: Boolean = true; 
 
  build() { 
    Row() { 
      Row({ space: 8 }) { 
 
        Text('正文列表') 
          .maxLines(1) 
          .fontColor(Color.Black) 
          .fontSize(17) 
          .fontWeight(FontWeight.Bold) 
          .textOverflow({ overflow: TextOverflow.Ellipsis }) 
          .layoutWeight(1) 
 
        Row() { 
          Text('正文列表正文列表正文列表正文列表正文列表') 
            .maxLines(1) 
            .fontColor(Color.Gray) 
            .textOverflow({ overflow: TextOverflow.Ellipsis }) 
            .fontSize(12) 
            .textAlign(TextAlign.End) 
          if (this.hasMore) { 
            Image($r('app.media.vod_media_right_more')) 
              .objectFit(ImageFit.Contain) 
              .size({ width: '15vp', height: '15vp' }) 
              .opacity(0.3) 
          } 
        } 
        .justifyContent(FlexAlign.End) 
      } 
 
      .width('100%') 
      .height(40) 
      .padding({ top: 8, left: 15, right: 15 }) 
    } 
 
    .height('100%') 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
HarmonyOS
2024-01-31 10:45:49
1.1w浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Bald_eagle

问题1:layoutWeight是占满剩下的空间,所以想达到效果是给正标题设置固定大小,副标题设置layoutWeight。

问题2:在弹性布局里面width(“100%”)一般不会与margin一起设置,这两个属性会有冲突。

问题3:以父容器大小为准。

分享
微博
QQ
微信
回复
2024-02-01 17:35:00


相关问题
如何指定组件宽高比?
946浏览 • 1回复 待解决
HarmonyOS 组件合理展示等相关问题
696浏览 • 1回复 待解决
Scroll组件展示位置如何调整
3160浏览 • 1回复 待解决
HarmonyOS 地图组件无法展示
827浏览 • 1回复 待解决
地图组件无法正常展示
1432浏览 • 1回复 待解决