当前位置:   article > 正文

HarmonyOS开发15:Text组件实例3——文本框展示大段文字_harmonyos的显示多行文本框

harmonyos的显示多行文本框

ability_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:alignment="center"
    ohos:orientation="vertical">

    <Text
        ohos:id="$+id:text1"
        ohos:height="100vp"
        ohos:width="300vp"
        ohos:background_element="#55121212"
        ohos:text="小明:你说我这穷日子过到啥时侯是个头啊?小红:那得看你能活多久了"
        ohos:text_size="40vp"
        ohos:truncation_mode="auto_scrolling"
        ohos:auto_scrolling_count="unlimited"
        ohos:auto_scrolling_duration="2000"
        />

</DirectionalLayout>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

截取模式:ohos:truncation_mode=“auto_scrolling”

  • ellipsis_at_start:前面内容省略
  • ellipsis_at_end:后面内容省略
  • ellipsis_at_middle:中间内容省略,但是需要组件足够宽
  • none:不做任何处理
  • auto_scrolling:滚动处理,(需要开启滚动)

滚动次数:ohos:auto_scrolling_count=“unlimited”

  • 整数表示滚动次数
  • unlimited:没有次数限制

滚动持续时间:单位是毫秒

  • auto_scrolling_duration=“1000”

MainAbilitySlice.java整体代码:

package com.example.textapplication.slice;

import com.example.textapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Text;

public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    Text text;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        
        //1. 获取Text
        text = (Text) findComponentById(ResourceTable.Id_text1);

        //2.给Text文本框添加事件,单击一下实现跑马灯
        text.setClickedListener(this);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        //开启跑马灯效果
        //两种方式可以获取文本对象
        //1.方法的参数,参数表示被点击的组件对象
        // Text t = (Text) component;
        // t.startAutoScrolling();

        //2.可以把onstart的text对象挪到成员位置
        text.startAutoScrolling();

    }
}

  • 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
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/238543
推荐阅读
相关标签