鸿蒙OS应用开发之——跑马灯效果
一 概述在鸿蒙OS应用中,Text不能直接作为布局文件使用,需要结合布局文件一起使用(Android中可以)public final void setUIContent(int layoutRes)public void setUIContent(ComponentContainer componentContainer)二、布局文件ability_main.xml<?xml version
·
一 概述
在鸿蒙OS应用中,Text不能直接作为布局文件使用,需要结合布局文件一起使用(Android中可以)
public final void setUIContent(int layoutRes)
public void setUIContent(ComponentContainer componentContainer)
二、布局文件
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"
>
<Text
ohos:id="$+id:text"
ohos:width="200vp"
ohos:height="match_content"
ohos:text="厦门大学欢迎您们!"
ohos:text_size="28fp"
ohos:text_color="#0000FF"
ohos:italic="true"
ohos:text_weight="700"
ohos:text_font="serif"
ohos:layout_alignment="horizontal_center"
ohos:background_element="$graphic:background_ability_main"/>
三、代码设置
MainAbilitySlice
public class MainAbilitySlice extends AbilitySlice {
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_main);
Text text = (Text) findComponentById(ResourceTable.Id_text);
// 跑马灯效果
text.setTruncationMode(Text.TruncationMode.AUTO_SCROLLING);
// 始终处于自动滚动状态
text.setAutoScrollingCount(Text.AUTO_SCROLLING_FOREVER);
// 启动跑马灯效果
text.startAutoScrolling();
}
四、效果图
更多推荐
已为社区贡献1条内容
所有评论(0)