HarmonyOS TextInput设置showCounter时,margin失效

HarmonyOS TextInput设置showCounter时,margin失效。

HarmonyOS
2024-10-10 10:21:15
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

可以参考demo:

@Entry  
@Component  
struct relativeLayoutExample {  
  build() {  
    RelativeContainer() {  
      Text('宽度')  
        .fontSize(12)  
        .padding({  
          left: 20,  
          right: 12  
        })  
        .fontColor('#222630')  
        .margin({  
          top: 20,  
          bottom: 20 //这里如果只设置margin-top,会导致后面TextInput组件在竖直方向上的锚点位置在Text组件中心偏上  
        })  
        .alignRules({  
          left: { anchor: '__container__', align: HorizontalAlign.Center },  
          top: { anchor: '__container__', align: VerticalAlign.Top }  
        })  
        .id('width-text')  
      TextInput()  
        .backgroundColor('#F7F7F8')  
        .showCounter(true)  
        .borderRadius(8)  
        .height(32)  
        .width(56)  
        .fontSize(14)  
        .maxLength(4)  
        .fontColor(Color.Black)  
        .type(InputType.Number)  
        .onChange(() => {  
        })  
        .margin({  
          top: 20,  
          bottom: 20 //这里如果只设置margin-top,会导致后面TextInput组件在竖直方向上的锚点位置在Text组件中心偏上  
        })  
        .alignRules({  
          center: { anchor: 'width-text', align: VerticalAlign.Center },  
          left: { anchor: 'width-text', align: HorizontalAlign.End }  
        })  
        .id('width-edit')  
    }  
    .width('100%')  
    .height(300)  
    .border({width:2, color: "#6699FF"})  
  }  
}
  • 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.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
分享
微博
QQ
微信
回复
2024-10-10 18:10:24


相关问题
span组件使用margin属性失效
2582浏览 • 1回复 待解决
控件enabled设置为false,hover失效
3222浏览 • 1回复 待解决
HarmonyOS 设置margin无效
588浏览 • 1回复 待解决
HarmonyOS 设置userAgent失效
636浏览 • 1回复 待解决
HarmonyOS WebView 圆角设置失效
815浏览 • 1回复 待解决
HarmonyOS 屏幕常亮设置失效
681浏览 • 1回复 待解决
HarmonyOS Span的属性设置失效
539浏览 • 1回复 待解决