鸿蒙开发中ScrollView用法的一个坑

文章讨论了在OHOS开发中,ScrollView内的DirectionalLayout高度设置对其子控件(TextView)内容滑动的影响。当height设为match_parent时,内容无法滚动;而设为match_content时,内容可滚动,这与Android的UI行为不同。
摘要由CSDN通过智能技术生成
<ScrollView
    ohos:width="match_parent"
    ohos:height="match_parent"
    ohos:background_element="#FFDEAD"
    >
    <DirectionalLayout
        ohos:width="match_parent"
        ohos:height="match_parent"
        ohos:scrollbar_color="#00ff00"
        ohos:orientation="vertical">
        <Text
            ohos:id="$+id:tv_many_words"
            ohos:width="match_content"
            ohos:height="match_content"
            ohos:scrollbar_color="#ff0000"
            ohos:margin="$float:common_margin_16"
            ohos:text_size="16fp"
            ohos:text_color="#333333"
            ohos:multiple_lines="true"/>
        <Text
            ohos:id="$+id:tv_many_words2"
            ohos:width="match_content"
            ohos:height="match_content"
            ohos:scrollbar_color="#0000ff"
            ohos:margin="$float:common_margin_16"
            ohos:text_size="16fp"
            ohos:text_color="#333333"
            ohos:multiple_lines="true"/>
    </DirectionalLayout>
</ScrollView>
<Text
    ohos:width="match_content"
    ohos:height="match_content"
    ohos:text_color="#15161E"
    ohos:text_size="16fp"
    ohos:multiple_lines="true"
    ohos:scrollable="true"
    ohos:text="往下就显示不出来了啊?"/>

如上图所示,这样的界面中,底部的文字控件是显示不出来的。这点和Android用法一样。

然后就是由于ScrollView的直接子视图DirectionLayout的height为match_parent,那么tv_many_words和tv_many_words内容是无法上下滑动的(ps:这两个的内容设置了很长的字符串)。

但是,如果DirectionLayout的height为match_content,那么其内部的两个文字控件内容是可以滑动的。这点和Android的用法貌似不一样。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值