当前位置:网站首页>Detailed explanation of the use of staticlayout
Detailed explanation of the use of staticlayout
2022-07-05 10:11:00 【A bird carved 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
边栏推荐
- 美图炒币半年亏了3个亿,华为被曝在俄罗斯扩招,AlphaGo的同类又刷爆一种棋,今日更多大新闻在此...
- Swift saves an array of class objects with userdefaults and nssecurecoding
- 【OpenCV 例程200篇】219. 添加数字水印(盲水印)
- 高级 OpenCV:BGR 像素强度图
- Baidu app's continuous integration practice based on pipeline as code
- isEmpty 和 isBlank 的用法区别
- How to use sqlcipher tool to decrypt encrypted database under Windows system
- Fluent generates icon prompt logo widget
- [200 opencv routines] 219 Add digital watermark (blind watermark)
- ThreadLocal source code learning
猜你喜欢

Design of stepping motor controller based on single chip microcomputer (forward rotation and reverse rotation indicator gear)

苹果 5G 芯片研发失败?想要摆脱高通为时过早

如何獲取GC(垃圾回收器)的STW(暫停)時間?

Unity particle special effects series - the poison spray preform is ready, and the unitypackage package is directly used - on

程序员搞开源,读什么书最合适?

卷起來,突破35歲焦慮,動畫演示CPU記錄函數調用過程

Apache dolphin scheduler system architecture design

Is it really reliable for AI to make complex decisions for enterprises? Participate in the live broadcast, Dr. Stanford to share his choice | qubit · viewpoint

一种用于干式脑电图的高密度256通道电极帽

历史上的今天:第一本电子书问世;磁条卡的发明者出生;掌上电脑先驱诞生...
随机推荐
Analysis on the wallet system architecture of Baidu trading platform
Unity粒子特效系列-毒液喷射预制体做好了,unitypackage包直接用 -下
面试:List 如何根据对象的属性去重?
Flutter development: a way to solve the problem of blank space on the top of listview
MySQL字符类型学习笔记
ArcGIS Pro creating features
Six simple cases of QT
双容水箱液位模糊PID控制系统设计与仿真(Matlab/Simulink)
Swift tableview style (I) system basic
Generics, generic defects and application scenarios that 90% of people don't understand
TDengine × Intel edge insight software package accelerates the digital transformation of traditional industries
Z-blog template installation and use tutorial
程序员如何活成自己喜欢的模样?
@SerializedName注解使用
Tianlong Babu TLBB series - about items dropped from packages
How to get the STW (pause) time of GC (garbage collector)?
Is it really reliable for AI to make complex decisions for enterprises? Participate in the live broadcast, Dr. Stanford to share his choice | qubit · viewpoint
How to correctly evaluate video image quality
【小技巧】获取matlab中cdfplot函数的x轴,y轴的数值
Applet image height adaptation and setting text line height