赞
踩
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>
截取模式: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();
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。