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

<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的用法貌似不一样。

猜你喜欢

转载自blog.csdn.net/yeziyfx/article/details/134163055
今日推荐