跑马灯效果实现效果图
注意事项:
HarmonyOS里面Text由于multiple_lines默认为false 所以我们可以直接来设置跑马灯效果,当想设置Text换行的时候设置multiple_lines为true ,所则就现显示不全如下
开始实现效果
layout 代码如下:
<?xml version="1.0" encoding="utf-8"?>
<DependentLayoutxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:height="match_parent"ohos:width="match_parent"ohos:alignment="horizontal_center"><Textohos:id="$+id:text"ohos:height="match_content"ohos:width="match_parent"ohos:text="静夜思,李白,窗前明月光,疑是地上霜,举头望明月,低头思故乡"ohos:text_size="22fp"ohos:top_margin="50vp"/></DependentLayout>
java 代码实现
public class IntentAbilitySlice extends AbilitySlice {@Overrideprotected void onStart(Intent intent) {super.onStart(intent);super.setUIContent(ResourceTable.Layout_intent_ability_slice_layout);Text text = (Text) findComponentById(ResourceTable.Id_text);// 跑马灯效果text.setTruncationMode(Text.TruncationMode.AUTO_SCROLLING);// 始终处于自动滚动状态text.setAutoScrollingCount(Text.AUTO_SCROLLING_FOREVER);// 启动跑马灯效果text.startAutoScrolling();}
}