一 概述
在鴻蒙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();
}
四、效果圖

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/246876.html
標籤:其他
下一篇:Cordova + vue 打包安卓(Android) apk 及 Apk版本自動升級及安裝(實時獲取下載進度)
