HarmonyOS 实现跑马灯效果
生活随笔
收集整理的這篇文章主要介紹了
HarmonyOS 实现跑马灯效果
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
跑馬燈效果實現效果圖?
注意事項:
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();}
}
總結
以上是生活随笔為你收集整理的HarmonyOS 实现跑马灯效果的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2020年10斤大米30元,价格会更高吗
- 下一篇: HarmonyOS Text设置换行