- This is the 9th day of my participation in the August More Text Challenge.
1. Text Displays a large Text box
- There are other ways to display large chunks of text
- It can be displayed in the form of horse-racing lantern, but two prerequisites are required, as follows:
The following two properties are default and can be omitted
ohos:truncation_mode="ellipsis_at_start"
, indicating that the previous content is omitted to”.
In the form of:
<Text
ohos:id="$+id:text1"
ohos:height="100vp"
ohos:width="100vp"
ohos:background_element="# 55121212"
ohos:text="Xiaoming: you say I this poor life lead to when hou is a head? Xiao Hong: That depends on how long you can live."
ohos:text_size="40vp"
ohos:truncation_mode="ellipsis_at_start"
/>
Copy the code
- Change the width to
300vp
- If you want to display the previous content, omit the following content, just put
ohos:truncation_mode="ellipsis_at_end"
ohos:truncation_mode="auto_scrolling"
Scroll effectohos:auto_scrolling_count="10"
The number of times the lantern is rolled, 10 means ten times,unlimited
Infinite number of timesohos:auto_scrolling_duration="2000"
It’s how fast you ran, 2000 is the unit of time, millisecond, how much time you ran, 2 seconds
2. Implementation cases
- New project: TextLargeApplication
ability_main
<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="Xiaoming: you say I this poor life lead to when hou is a head? Xiao Hong: That depends on how long you can live."
ohos:text_size="40vp"
ohos:truncation_mode="auto_scrolling"
ohos:auto_scrolling_count="unlimited"
ohos:auto_scrolling_duration="2000"
/>
</DirectionalLayout>
Copy the code
MainAbilitySlice
package com.xdr630.textlargeapplication.slice;
import com.xdr630.textlargeapplication.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 {
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_main);
/ / 1. Access to the Text
Text text1 = (Text) findComponentById(ResourceTable.Id_text1);
//2. Add a click event to the Text
// Indicates that when clicked, the running light effect is enabled
text1.setClickedListener(this);
}
@Override
public void onActive(a) {
super.onActive();
}
@Override
public void onForeground(Intent intent) {
super.onForeground(intent);
}
@Override
public void onClick(Component component) {
// Turn on the running light effect
// Two ways to get text objects
//1. The argument to the method represents the object of the component being clicked
//2. We can move the Text object in onStart to the member position
// Use the first method to implement:
// Force first, because the running light method is not in the parent component class, but in the Text Text
// So make Component strong TextText t = (Text) component; t.startAutoScrolling(); }}Copy the code
- Run:
- Because it’s set
auto_scrolling_count="unlimited
Property, so it scrolls an infinite number of times. You can also set how many times to scroll, and how long to scroll.