当前位置:网站首页>Usage details of staticlayout
Usage details of staticlayout
2022-06-28 02:52:00 【An eagle in the desert】
stay Android In development ,Canvas.drawText Don't wrap , Even a very long string will only display one line , The excess will be hidden from the screen .
StaticLayout yes android A tool class for processing text in ,StaticLayout Solved the problem of word wrapping , As an example :
package com.zhy.someuitest;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Nullable;
public class StaticLayoutView extends View {
StaticLayout staticLayout;
public StaticLayoutView(Context context) {
this(context, null);
}
public StaticLayoutView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public StaticLayoutView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
textPaint.setColor(Color.BLACK);
textPaint.setStyle(Paint.Style.FILL);
textPaint.setTextSize(50);
String text = " stay Android In development ,Canvas.drawText Don't wrap , Even a very long string will only display one line , The excess will be hidden from the screen .StaticLayout yes android A tool class for processing text in ,StaticLayout Solved the problem of word wrapping ";
staticLayout = new StaticLayout(text, textPaint, canvas.getWidth(), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
staticLayout.draw(canvas);
}
}

Staticlayout There are three construction parameters in :
With public StaticLayout(CharSequence source, int bufstart, int bufend,
TextPaint paint, int outerwidth,
Alignment align,
float spacingmult, float spacingadd,
boolean includepad,
TextUtils.TruncateAt ellipsize, int ellipsizedWidth) {
this(source, bufstart, bufend, paint, outerwidth, align,
TextDirectionHeuristics.FIRSTSTRONG_LTR,
spacingmult, spacingadd, includepad, ellipsize, ellipsizedWidth, Integer.MAX_VALUE);
} Explain the function of parameters
CharSequence source Need a string of branches
int bufstart The string that needs to be branched starts at the position of
int bufend Where does the string for the branch end
TextPaint paint Brush object
int outerwidth layout Width , Wrap when exceeded
Alignment align layout The right way to do it , Yes ALIGN_CENTER, ALIGN_NORMAL, ALIGN_OPPOSITE Three
float spacingmult Relative row spacing , Relative font size ,1.5f Indicates that the line spacing is 1.5 Times the font height .
float spacingadd How much to add to the base line spacing
boolean includepad,
TextUtils.TruncateAt ellipsize Where to start omitting
int ellipsizedWidth More than how many begin to omit
Add :TextView In fact, it is also used StaticLayout
边栏推荐
- 设计电商秒杀系统
- 贪吃蛇 C语言
- 无心剑汉英双语诗004.《剑》
- [today in history] May 31: the father of Amiga was born; The co developer of basic language was born; BlackBerry BBM shutdown
- 数仓的字符截取三胞胎:substrb、substr、substring
- 毕业季来临,2022届高校毕业生人数首次突破千万大关
- [today in history] June 15: the first mobile phone virus; AI master simahe was born; Chromebook launch
- 【 amélioration de la correction d'image de Code bidimensionnel】 simulation du traitement d'amélioration de la correction d'image de Code bidimensionnel basée sur MATLAB
- [today in history] June 3: Microsoft launched Bing search engine; Larry Roberts starts ARPANET; The father of Visual Basic was born
- 云原生(三十) | Kubernetes篇之应用商店-Helm
猜你喜欢
![[today in history] June 5: Lovelace and Babbage met; The pioneer of public key cryptography was born; Functional language design pioneer born](/img/af/1faf1df4262940e73104ed2880f08d.png)
[today in history] June 5: Lovelace and Babbage met; The pioneer of public key cryptography was born; Functional language design pioneer born

STM32的C语言与汇编语言混合编程
![[today in history] June 1: Napster was founded; MS-DOS original author was born; Google sells Google SketchUp](/img/fe/497eab2ac4a762298e71d28ed26e41.png)
[today in history] June 1: Napster was founded; MS-DOS original author was born; Google sells Google SketchUp

Intel Ruixuan A380 graphics card will be launched in China

Reprinted article: the digital economy generates strong demand for computing power Intel releases a number of innovative technologies to tap the potential of computing power

> Could not create task ‘:app:MyTest. main()‘. > SourceSet with name ‘main‘ not found. Problem repair

Arduino Esp8266 Web LED控制

How to run unity webgl after packaging (Firefox configuration)
![[fuzzy neural network] simulation of fuzzy neural network based on MATLAB](/img/2f/ffe3baf37808b78b2c299aef5a717e.jpg)
[fuzzy neural network] simulation of fuzzy neural network based on MATLAB

为什么大厂压力大,竞争大,还有这么多人热衷于大厂呢?
随机推荐
ROS+Gazebo中红绿黄交通灯如何实现?
Publicity of the third batch of shortlisted enterprises! Annual Top100 smart network supplier selection
Différences d'utilisation entre IsEmpty et isblank
LiveData 面试题库、解答---LiveData 面试 7 连问~
CRF+BiLSTM代码分步骤解读
MFC CString to LPVOID
面试:Bitmap像素内存分配在堆内存还是在native中
[2D code image correction and enhancement] simulation of 2D code image correction and enhancement processing based on MATLAB
Skills in schematic merging
How technicians become experts in technical field
STM32F1与STM32CubeIDE编程实例-金属触摸传感器驱动
4G-learn from great partners
[today in history] June 5: Lovelace and Babbage met; The pioneer of public key cryptography was born; Functional language design pioneer born
抓包整理外篇fiddler————了解工具栏[一]
在线JSON转PlainText工具
【历史上的今天】6 月 16 日:甲骨文成立;微软 MSX 诞生;快速傅里叶变换发明者出生
【历史上的今天】6 月 7 日:Kubernetes 开源版本发布;《魔兽世界》登陆中国;分组交换网络发明者出生
Win11不能拖拽圖片到任務欄軟件上快速打開怎麼辦
Prometheus 2.27.0 new features
Win11不能拖拽图片到任务栏软件上快速打开怎么办